Frank wrote in one of his last posts about the new sticky functionality in WordPress 2.7. Right now I’m working on a special theme and I noticed some strange things with sticky posts.
Wrong Post Count
If you like to show 6 posts on a page, I use
query_posts('showposts=6');. But if one or more posts are “sticky”, they get added to the other 6 posts. To show 6 posts actually, you have to know how many sticky posts you have.
get_option('sticky_post') gives you an array back with sticky post ID, which we can count.
$sticky = count(get_option('sticky_posts')); query_posts('showposts='. ( 6 - $sticky ));
Still showing sticky posts in chronological sort order
Pay attention to the CSS classes of the posts. The template tag
post_class() gives the post the class. In the case of sticky post, it is also the class “sticky”. If you think you can give the class sticky a red background and black border to have a nice teaser you will be disappointed. If you go to the next page to see previous posts, the sticky post will also be showed in the chronological order with a red background and black borders. Not really cool.
Kill the Sticky
If you don’t want to have sticky posts, just write in your template:
With the empty array you overwrite the sticky options and no sticky posts are availably.