Skip to content

Instantly share code, notes, and snippets.

@wpmark
Last active August 29, 2015 14:06
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 wpmark/aa388261d0ef58938218 to your computer and use it in GitHub Desktop.
Save wpmark/aa388261d0ef58938218 to your computer and use it in GitHub Desktop.
Show Only 5 Blog Posts on Home Page
<?php
/***************************************************************
* Function wpmark_alter_homepage_posts_query()
* Alter query on homepage for show just 5 posts
***************************************************************/
function wpmark_alter_homepage_posts_query( $query ) {
/* check this is not the main query, the admin - if so bail early */
if( ! $query->is_main_query() || is_admin() )
return;
/* check whether this is the job post type archive or a job tax archive */
if( is_home() ) {
/* set job archives to show 10 posts per page */
$query->set( 'posts_per_page', 5 );
}
return;
}
add_action( 'pre_get_posts', 'wpmark_alter_homepage_posts_query', 10 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment