Feature
Post

Category
Code


Getting Ready for WordPress 2.7: Sticky Post Styling

Sticky posts are a new feature in WordPress 2.7. Basically, it means that you can mark a post as sticky, which means it’ll stay at the top of your post listing until another sticky one shuffles it down. More or less like sticky posts on forums.

This has been possible previously as well, with a plugin by Lester Chan.

WordPress 2.7 is out in beta, and isn’t due until later this month (late, most likely), but you might want to get your themes ready for this new functionality. You do have to change your post class output to post_class, which I detailed here.

This is what you need to add to your style.css:

[CSS].sticky { background: #bbb; }[/CSS]

That’s right, it is just one simple little class, .sticky, for you to add to your stylesheet. The code above will just give the sticky post a grey background color, so how about we do something more funky?

[CSS].sticky {
font-size: 24px;
border: 1px solid #bbb;
border-width: 1px 0;
background: #eee;
padding: 15px;
}[/CSS]

That would give us a box with large text, a grey border in the top and bottom, and a light grey background, with 15 pixels padding. Naturally, you’d have to style your sticky posts for your design, this is just to give you something to think about to highlight your headlining posts in the future.

Remember, this won’t work with versions of WordPress prior to 2.7!


  1. By dinu posted on November 6, 2008 at 2:36 am
    Want an avatar? Get a gravatar! • You can link to this comment

    tried this on cutline theme, dint work, will check it again update you :)

  2. By stratosg posted on November 8, 2008 at 8:24 am
    Want an avatar? Get a gravatar! • You can link to this comment

    very nice post man… i was really into how sticky posts would work. thx!

  3. By Prasannah posted on November 8, 2008 at 10:38 pm
    Want an avatar? Get a gravatar! • You can link to this comment

    yeah.. doesn’t work with darren hoyt’s agregado theme either! :(

  4. By Tony K posted on November 9, 2008 at 5:57 pm
    Want an avatar? Get a gravatar! • You can link to this comment

    Doesn’t work. Is there other code to edit? I even checked the 2.7 default theme for .sticky anywhere and nothing.

  5. By Daniel K posted on November 21, 2008 at 5:13 pm
    Want an avatar? Get a gravatar! • You can link to this comment

    The beta’s for 2.7 aren’t passing .sticky as a class yet when you use it. The is_sticky() is working though.

  6. By Daniel K posted on November 21, 2008 at 5:18 pm
    Want an avatar? Get a gravatar! • You can link to this comment

    I just got it to work. You need to use the post_class().

    <div id=”post-“>

  7. By Mike posted on December 26, 2008 at 6:59 am
    Want an avatar? Get a gravatar! • You can link to this comment

    Hi, Daniel, can you tell more detail? I am not familiar with the code modification.
    Thanks.

  8. By sedill posted on December 30, 2008 at 3:44 pm
    Want an avatar? Get a gravatar! • You can link to this comment

    Great! It worked, along with the post_class tag!
    Mike, just follow the instructions you find via the link on top of this post. After that, follow instructions given in this post here.

    Thank you very much, exactly what I was looking for, made my day!

  9. TrackbackAndySowards.com :: Web Development Nerdy Daily Links For 11/05/2008 :: 50th Post!! | AndySowards.com :: Professional Web Design, Development, Programming, Hacks, Downloads, Math and being a Web 2.0 Hipster?Freelance Friday: My Writing Week 45 | tdhedengrenWordPress Wednesday News: WordPress 2.7 Beta 2, Danger WordPress Faker, and More WordCamps | The Blog HeraldWordPress 2.7 News « Lorelle on WordPressWordpress 2.7 ChecklistGetting Ready for WordPress 2.7: Really Simple Category Styling | DevloungeFun with WordPress 2.7: Adding Asides without Hacking the Loop | DevloungeHey Sandboxers, How About an Update! (OR How to Update the Sandbox Theme to Work With WordPress 2.7) | DevloungeHey Sandboxers, How About an Update! (OR How to Update the Sandbox Theme to Work With WordPress 2.7)Getting Ready for WordPress 2 7 Sticky Post Styling Devlounge | Outdoor Ceiling Fans