• I’m using the default Loop Code.

    I’ve set the ‘Blog pages show at most’ option in Settings > Reading to 11.

    In my home page -set to show Latest Posts- whenever I mark a post as ‘Sticky’ it’s being added to the original ‘Blog pages show at most’ count, so the home page now shows 12 posts instead of 11.

    I want to avoid this!

    I want to keep 11 posts in total, that being -in the example above- 1 Sticky post plus 10 normal posts. Is this possible?

    I’ve already tested this with default themes and all plugins turned off.

    Any help will be very much appreciated.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    It’s possible, but it’s sort of a mess. The issue is WP sticks the sticky posts at the top after the main query has already run to retrieve however many posts you specified. It’s not just a theme issue as you have discovered. In order to always have the same number per page, you basically have to run two queries and loops, one for the stickies, then one for the regular posts. Not too bad if just that. You also will need to manage pagination because the number of stickies changes which slice of results to query for for each page. Even though the stickies typically appear on just the first page, the space they take up influences all the pages.

    You can still use the main query for the second loop, but you will need to modify it through the ‘pre_get_posts’ action to provide an ‘offset’ parameter. See Making Custom Queries using Offset and Pagination for more on what’s involved in handling pagination.

Viewing 1 replies (of 1 total)
  • The topic ‘How to include sticky posts in 'Blog pages show at most' X number of posts?’ is closed to new replies.