We often have some posts that we would like to promote and keep at the first page of the blog. When you are using pagination, the sticky posts will be added to the standard posts, making the post count per page uneven.
If you want to keep your posts per page count consistent, there is a way to do that.
PREPARE PAGINATION
1 2 3 4 5 6 7 8 9 10 11 12 13 |
global $paged; if (!isset($paged) || !$paged){ $paged = 1; } // Set posts per page $posts_per_page = 8; // Get sticky posts $sticky = get_option( 'sticky_posts' ); |
SWITCH QUERY FOR FIRST PAGE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
// First page and has stickies if($paged == 1 && !empty($sticky)) { $args = array( 'post_type' => 'post', 'paged' => $paged, // Adjust posts per page by subtracting the amount of stickies 'posts_per_page' => $posts_per_page - count($sticky) ); }else{ $args = array( 'post_type' => 'post', 'paged' => $paged, 'posts_per_page' => $posts_per_page, // making sure the 2nd page starts with the right post 'offset' => (($paged-1)*$posts_per_page) - count($sticky) ); } // Do query query_posts($args); |