WP Query – Alternative Number Of Posts On Paged Results


About The Author
Cabe Nolan is the founder of WP Cover where he shares his insight into WordPress, development, & entrepreneurship. Outside of WPCover, Cabe continues to run a successful WordPress development firm, Bold City Design as well as a few high profile websites, Arrivala, Two Way Resume, Dock Skipper, and a successful outdoors brand, DolfinPack.







WP Query – Alternative Number Of Posts On Paged Results

Have you ever needed to show an alternative number of posts on the first page of the results versus the paged results?  It’s kind of a design trend right now by giving the most recent post prominance but in return, you often give an uneven number of posts within your grid.  Luckily for you, the fix is simple and clean:

My initial query looked something like this:

$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$query_args = array(
  'post_type' => 'my-post-type',
  'posts_per_page' => 10,
  'paged' => $paged
);
$the_query = new WP_Query( $query_args );

To modify the limit based on whether or not the results had been paged, my modification was simply:

$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
if( $paged == 1 ) {
   $limit = 10;
} else {
   $limit = 9;
}
$query_args = array(
  'post_type' => 'my-post-type',
  'posts_per_page' => $limit,
  'paged' => $paged
);
$the_query = new WP_Query( $query_args );

BOOM! Go enjoy the rest of your day :).


Share Your Thoughts

Leave a Reply

Your email address will not be published. Required fields are marked *


Related Stuff You Might Like







WordPress News, Tips, & Code Snippets

Join the WP Cover mailing list and get wordpress news, tips, code snippets, security warnings, and more delivered right to your inbox.  We won't flood your inbox, newsletters typically go out every 1-2 weeks unless it involves an important security release.

You have Successfully Subscribed!