Skip to content

Instantly share code, notes, and snippets.

@srikat
Last active February 24, 2016 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srikat/cdc430734b353fb57793 to your computer and use it in GitHub Desktop.
Save srikat/cdc430734b353fb57793 to your computer and use it in GitHub Desktop.
Displaying a fixed number of Posts in WordPress without Pagination. https://sridharkatakam.com/displaying-a-fixed-number-of-posts-in-wordpress-without-pagination/
add_action( 'pre_get_posts', 'be_change_home_posts_per_page' );
/**
* Change Posts Per Page for Posts page
*
* @author Bill Erickson
* @link http://www.billerickson.net/customize-the-wordpress-query/
* @param object $query data
*
*/
function be_change_home_posts_per_page( $query ) {
if( $query->is_main_query() && !is_admin() && is_home() ) {
$query->set( 'posts_per_page', '3' );
}
}
add_action( 'pre_get_posts', 'be_change_home_posts_per_page' );
/**
* Change Posts Per Page for Posts page
*
* @author Bill Erickson
* @link http://www.billerickson.net/customize-the-wordpress-query/
* @param object $query data
*
*/
function be_change_home_posts_per_page( $query ) {
if( $query->is_main_query() && !is_admin() && is_home() ) {
$query->set( 'posts_per_page', '3' );
$query->set( 'no_found_rows', true );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment