WP Query – Alternative Number Of Posts On Paged Results
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