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

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

>

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 )

Posted

in

by

Comments

9 responses to “Sticky Function in WordPress 2.7”

  1. […] 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 […]

  2. sandy Avatar
    sandy

    Nice to read.Thank u

  3. ross Avatar

    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?

  4. Alex Avatar

    @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. 🙂

  5. Jeremy Avatar

    @Alex,

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

  6. Alex Avatar

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

  7. eduardo Avatar
    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

  8. Dian Avatar

    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

  9. Mark Avatar
    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.