[wp-hackers] Sticky posts and Posts Per Page
Erick Hitter
ehitter at gmail.com
Tue Aug 3 17:00:56 UTC 2010
Jake,
What if you used the count of sticky posts to adjust the limit specified in
the SQL query through the *post_limits* filter? Based on the number of
sticky posts and the page currently displayed, you should be able to reduce
the posts returned by the original query proportionally. So, if there are
two sticky posts, the original query would be reduced to return one post.
Then, when *get_posts* reaches the stickies part of its process, it would
place the two sticky posts ahead of the one post the original query
returned. This should work because if *get_posts* doesn't find the sticky
posts in the results of the original query, it prepends them to the original
result.
Erick
On Tue, Aug 3, 2010 at 12:42, Jake Goldman <
wphackers at jakemgold.myfastmail.com> wrote:
> Anyone know of an "elegant" solution for getting sticky posts to count
> toward the posts per page limit?
>
> The use case here is a /very /formatted 3x3 grid output for posts. The
> client wants to be able to use sticky posts to feature his best work, but it
> can't break the 3x3 grid. Out of the box, sticky posts get added on top of
> the posts per page count.
>
> Keep in mind that there are dozens of posts already - so paging is
> important. I can't simply count up the sticky posts and subtract from posts
> per page (setting a new posts_per_page) without breaking paging.
>
> Using count of stickies - posts_per_page for page 1 and then using an
> offset on subsequent pages would work if I could have a negative offset
> (which it seems I can't). It gets even more complicated if the there are
> more sticky posts than there are post blocks on the first page (9), but I
> can impose rules to limit the site to a maximum of 9 sticky posts.
>
> I have a few hack-ish ideas, but I thought I'd pose the question first in
> case anyone has dealt with this limitation before.
>
> Jake
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list