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

WP SITES

2671

Original Genesis Tutorials & 5000+ Guaranteed Code

Snippets

  • Tutorial Requests
  • Contact
  • Videos
  • Tags
  • Log in

Premium Member? - Request custom code

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.

pre_get_posts

Reader Interactions

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Brad Dalton Specializes In Genesis child theme customization & code modification. Read More…

Learn PHP Code

template_include

get_body_class

if else

array

class_exists

foreach

sprintf

add_action

printf

variable

Advertise · WPEngine · Genesis · Log in

  • How Premium Membership Works
  • Sign Up
  • Support
  • Subscription Details/Invoice
  • Tagged Tutorials
  • Access-Download Problems