Skip to content

Instantly share code, notes, and snippets.

@jfcode
Created May 20, 2014 04:22
Show Gist options
  • Save jfcode/e6695bcec8cca4b37d86 to your computer and use it in GitHub Desktop.
Save jfcode/e6695bcec8cca4b37d86 to your computer and use it in GitHub Desktop.
Control number of posts on home page and category
function hwl_home_pagesize( $query ) {
if ( is_admin() || ! $query->is_main_query() )
return;
if ( is_home() ) {
// Display only 3 posts
$query->set( 'posts_per_page', 3 );
return;
}
if ( is_archive() ) {
// Display only 5 posts
$query->set( 'posts_per_page', 5 );
return;
}
}
add_action( 'pre_get_posts', 'hwl_home_pagesize', 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment