• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2762

Original Genesis Tutorials & 6000+ Guaranteed Code

Snippets

  • Premium Access
  • Log in

Set Posts Per Page For Any Archive Type

Use this code in your child themes functions file with a conditional tag to target a specific archive page type to set posts per page.

add_action( 'pre_get_posts', 'set_posts_per_archive_page' );
 
function set_posts_per_archive_page( $query ) {
 
if ( ! is_admin() && $query->is_main_query() ) {
 
    $query->set('posts_per_page', '5');
 
    }
}

The above code sets all archive pages to display 5 posts per page.

Post Per Page For Specific Category #

Only executes on the news category archive page.

add_action( 'pre_get_posts', 'set_posts_per_archive_page' );
 
function set_posts_per_archive_page( $query ) {
 
if ( ! is_admin() && $query->is_main_query() && is_category( 'news' ) ) {
 
    $query->set('posts_per_page', '1');
 
    }
}

Swap out the slug news in the above code to target a different category.

Swap out the 1 to change the number of posts per page you want to display on the archive page.

Subscribe for new Tutorials

pre_get_posts

Reader Interactions

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Code written by Brad Dalton specialist for WooCommerce & WordPress theme customization. Read More…

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting