Sticky Function in WordPress 2.7

Flag for Sticky in WP 2.7

Flag for Sticky in WP 2.7


With WordPress 2.7 you are able to make a post sticky, so this particular post will be showed on the top always. Before that you had to use a Plugin.

You can activate this setting for a post in the publish area, where you edit the publish date. It's pretty easy to do.

But what, if you like to format the sticky post? For this matter there is a new function - post_class(). This gives classes for the different posts, also the class sticky, if it's a sticky post.

Additionally are classes for categories and tags available. An example here with some information.

Example Output

<div id="post-12" class="post sticky hentry category-general category-wordpress tag-survey tag-wordpress">

The above output is a result of following code in the template:

<div id="post-<?php the_ID(); ?>" <?php post_class() ?>>

This function creates different classes, whereas

  • the class of the kind of post to show - post
  • if it's a sticky post - sticky
  • for hAtom - hentry (check shema microformats)
  • all categories, which the post belongs to
  • and all tags, which were assigned.

This function can also create additional classes. Very useful if you use a theme before WordPress 2.7 you like to enhance, but already is in use of a class.

post_class( 'my_class')

Furthermore you can also deliver the ID of a post. You get from this post the classes. For example:

post_class( 'my_class', '9')

The function looks like this in standard.

post_class( $class = '', $post_id = null )

Comments are closed.

9 comments

  1. sandy

    Nice to read.Thank u

  2. ross

    Just upgraded to wordpress 2.7 but am unable to find the 'sticky' option when publishing posts. Is there an option to turn this feature on?

  3. Alex

    @Ross, above the button Publish Post, there is Visibilty, click on Edit next to it and it will show the option to make it sticky. 🙂

  4. Jeremy

    @Alex,

    I don't have that option there for some reason, even though I'm running 2.7, any ideas?

  5. Alex

    @Jeremy, hmm, that is very odd. Is there a Visibility button and if so, what is it showing if you click on Edit?

  6. eduardo

    great examples. wp rocks!! i have aquestion about sticky post: how can you call only the first 3 sticky post? i coded this but it doesn't seems to work:

    3,); query_posts($args); ?>

    please help me, i know this question maybe a little amateur but i cant figure it out! for now i am only showing the latest sticky but i want to make like a "dynamic showing thing" with jquery... great page by the way it was really helpful when i was starting in wordpress last month

  7. Dian

    It would be nice if some of those default classes could be excluded.

    I don't really need anything but odd/even and sticky classes

  8. Mark

    My WP installment doesn't have the sticky option on the normal editing page, but it IS available while using the "quick edit" option. Weird, but at least it gets the job done.

One pingback

  1. Strange Things With Sticky Posts - WP Engineer