post_class(); … Take advantage of the new "Sticky Post" feature in WordPress 2.7

Of the many excellent new features coming in WordPress 2.7, some are applauding the arrival of sticky posts.

First – what are they? Sticky posts are posts that you can “stick” to your front page. For instance, if you have a post that you published a year ago and would like to republish it to the front page of your site for a time – you can edit that post and select “Stick this post to the front page” in the Edit Post page in your WordPress admin panel. Just doing that will stick it to your front page, ahead of all the other posts on your site.

You can use CSS to style those sticky posts, as well. All you need is this markup:

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

That will insert a class=”sticky” above your post and you can use CSS to style .sticky. Cool, eh?

More? Yes, there is more. That same tag will insert special classes for your categories and tags, as well. An example?? I’m glad you asked! Hypothetically, I have a sticky post that I’ve filed in the Misc category and tagged with News, WordPress and Markup. With me so far? With all of that, plus the post_class(); tag in my template – my source code for that particular post looks like this:

<div id="post-ID" class="post sticky hentry category-misc tag-news tag-wordpress tag-markup">

Now, I can use CSS to create special styles for the following classes:
- .post
- .hentry
- .sticky
- .category-misc
- .tag-news
- .tag-wordpress
- .tag-markup

I forsee lots of people having lots of fun with this! I am doing some custom work for some clients 2.7 (beta) right now, with the intention to launch them once 2.7-final is released. I’m having good fun working with the new post_class(); tag and the new features of sticky posts, threaded and paged comments. I’m excited for WordPress to release 2.7-final into the wild!

Owner and Creative Designer for E.Webscapes Design Studios and Lead Developer/WP Architect at Convertiv. She is also the author of WordPress For Dummies. On the web » Blog | Twitter | Facebook

26 Responses to post_class(); … Take advantage of the new "Sticky Post" feature in WordPress 2.7

  1. It’s about friggin’ time!

  2. I know, right? yahoo!

  3. Lisa,
    Not to try to pimp out my own content, but I really do thing the post I wrote yesterday would be a worthwhile read and/or bookmark for you and your readers.
    http://www.nathanrice.net/blog/definitive-sticky-posts-guide-for-wordpress-27/

    I tried to cover everything I could about the upcoming Sticky Post feature.

    Thanks!
    Nathan

  4. Nathan – - of course you meant to pimp your own content!
    That’s cool because your post is v. helpful – thanks for sharing it!:)>-

  5. I am going to play around till the release, and hopefully get my new site built for the WP community looking pretty in 2.7!

  6. I am using 2.63 and I just installed a sticky-plugin that is less than great. So, when I read this I almost jumped for joy. This is a much needed addition.

  7. Hi there! That’s so cool a second edition of your book is coming out; any chance I could buy a signed copy perhaps?

    Have a great Turkey Day – and keep it phunkay!

  8. Sure seems like a more practical solution than continuously changing the date of the post, which is what one of my friends does.

  9. Those snow flakes are annoying.

  10. Pingback: 10 ways to make your wordpress theme look like pro. » GoSee-Design › lifestory of a freelance team

  11. Pingback: 10 ways to make your wordpress theme look like pro. – jpablobr.com

  12. Really great post! I’ll even overlook the Pink!

  13. Pingback: 10 Useful WordPress Coding Techniques « Smashing Magazine

  14. Pingback: 10 Useful WordPress Coding Techniques « Tech7.Net

  15. Pingback: 10 Useful WordPress Coding Techniques | Search Engine Optimisation

  16. Pingback: 10 Useful WordPress Coding Techniques – My Facebook

  17. Pingback: Web Design News » 10 Useful WordPress Coding Techniques

  18. Pingback: WordPress Coding Techniques : Style Posts Individually

  19. Hey I was wondering how to create a unique style for a post and call that style with the post_class() or post_ID(). I don’t want to edit the .post style because it would change the whole layout of the posts, I just want to change the text alignment to left on the single post page. Thanks!
    *Note: The website I listed is my own website, and not the wordpress one that I’m working on

  20. Remember, you can take this even further by adding your own tags in to the post_class, such as:

    This can lead to all sorts of possibilities:
    - Easier styling for individual posts (to achieve a jasonsantamaria style site perhaps)
    - Different styles for different authors.
    - Different style for each month?

  21. Excellent trick. and nice function added by wordpress in 2.8 now we can style post according to the post category or posts tags.

  22. Pingback: Use WP template post-class() to style posts individually | WebDesign Collection

  23. Pingback: post_class(); … Take advantage of the new “Sticky Post” feature in WordPress 2.7 | Lisa Sabin-Wilson | WordPress News

  24. Pingback:   10 Useful WordPress Coding Techniques by Oshoamy

  25. Pingback: Geek is a Lift-Style. »Archive » 10 Useful WordPress Coding Techniques

Click on a tab to select how you'd like to leave your comment

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>