Lisa Sabin-Wilson. Designer. Author. Espresso and WordPress addict

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

on: Nov/12/08 and its been viewed 821 times

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 <?php post_class() ?> id="post-<?php the_ID(); ?>">

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 class="post sticky hentry category-misc tag-news tag-wordpress tag-markup" id="post-ID">

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

As an example, the code in your index template (and/or single/archive templates) may look like this:

<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h3 class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Article about: <?php the_title(); ?>"><?php the_title(); ?></a></h3>
<?php the_content('<span class="more-link">'.__('Read More &raquo;').'</span>'); ?>
</div>
<?php endwhile; else: ?>
<?php _e('Sorry, no posts matched your criteria.'); ?>
<?php endif; ?>

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!

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • BlinkList
  • blogmarks
  • E-mail this story to a friend!
  • Fark
  • Furl
  • LinkedIn
  • Ma.gnolia
  • MySpace
  • Ping.fm
  • Reddit
  • Slashdot
  • SphereIt
  • StumbleUpon
  • TwitThis
  • Yahoo! Buzz

Posted on: November 12, 2008

Posted in: Blog Design, CSS, Design, WordPress, Wordpress Themes

Tags: , , , ,

/*--- 10 Responses to “post_class(); … Take advantage of the new “Sticky Post” feature in WordPress 2.7” ---*/

  1. Danalyn
    2:02 am on November 12th, 2008

    It’s about friggin’ time!

  2. Lisa
    2:11 am on November 12th, 2008

    I know, right? yahoo!

  3. Nathan Rice
    9:46 am on November 12th, 2008

    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. Lisa
    2:23 pm on November 12th, 2008

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

  5. TheFrosty
    2:51 pm on November 12th, 2008

    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. Kristina Brooke
    8:58 pm on November 22nd, 2008

    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. Rob Brennan
    10:55 am on November 24th, 2008

    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. Barbara Ortagus
    4:00 pm on December 3rd, 2008

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

  9. Beu
    7:31 pm on December 19th, 2008

    Those snow flakes are annoying.

  10. Lisa
    7:45 pm on December 19th, 2008

    Thanks for the feedback, Beu - I happen to like ‘em. :)

    Happy holidays!

Leave a Reply

  • Li-sa Sa-bin Wil-son: [lee-suh sey-bin will-sun] - pronoun; 1. A wife, mother & friend; 2. Blog Designer & WebHost; 3. Author of WordPress For Dummies; 4. Scuba diver; 5. Downhill Skier; 6. Am. Photographer; 7. Espresso sipper;
    contact me »
    WordPress For Dummies, author Lisa Sabin-Wilson, Amazon.ComWordPress For Dummies, 2nd Ed. is due to be released early in 2009. It covers WordPress.com and WordPress.Org through version 2.7. I will update my site when I have a firm date you can count on...read more »

  •  

    • I was interviewed by Grant Friendman of Colorburned - he has it up on his site this morning. I talk design, tools, WordPress, blogs and life experiences that lead me to the career I'm enjoying now. Thanks, Grant!

      - #
    • Thanks to WPZoom for including me in their talented list of WordPress "Rockstars".

      - #
    • I'm scheduled to appear on the WordPress Weekly show on Fri. 11/28 - starting at 8pm and goes until... well, until we're done. We'll be talking WordPress For Dummies and WordPress 2.7. Check out Jeff's WordPress Weekly information page to find out how you can listen in..and even call-in and participate!

      - #
    • I just donated to the prize pool for the WordPress MU Plugin Competition. REALLY looking forward to the great MU plugins they come up with! What a great idea! Are you a plugin developer? Well get over there and enter...and win! :)

      - #
    • The panel picker for SXSW 09 is now live and you're able to vote for panels/presentations you'd like to see at SXSW in Austin in March 09. My Panel on WordPress Magazine Theming is up, if you're care to cast your vote for it - I'd surely appreciate it! It's the ONLY prospective panel at SWSX about WordPress - - let's get WP represented!! Go here to cast your vote and thanks!

      - #
    • Lisa: @Tech - I’m not sure about physical bookstores in...
    • TheFrosty: I would love to check that out!
    • techandlife: What about overseas release Lisa? Does Feb 17th also...
    • Lisa: Neville, great to hear from you. I surely appreciated our...
    • Neville Hobson: Great news, Lisa. Although I’ve been blogging...
    • Lisa: Dave, thanks for dropping by - happy to hear that the book...
    • Dave Schlottman: Thanks for the heads up on the release date for...
    • Lisa: Good to hear, Gary - - I still have the picture you sent me...
    • Gary LaPointe: Very exciting! As I’ve been doing more and...
    • release date | Lisa Sabin-Wilson: time, when the 1st Edition was...
    • Lisa: I love 2.7, Marc - but I suppose it’s all a matter of...
    • Lisa: Happy to help, K. :) My husband often talks about moving to...
    • KTown: Lisa, I’m getting ready to move back to Wisconsin (my...
    • Marc McDermott: I have to say that I was not so much impressed with...
    • Lauren: Thank you so much for the tip. I got the same exact...