Styling the first post of your Wordpress blog

I got several emails when I had published my new site design about how to style only the first post of the blog in Wordpress. This tactic can be handy to call out the very first post so that the readers attention is on the most recent topic for your blog. It is actually very easy, and may not be the best PHP in the world but it works perfectly.

Now the only problem with using this method is that you will have every first post on every index page styled this way. I haven’t played around with how to avoid that because that is the way I intended to design it. Perhaps someone has an idea on avoiding that if it is needed.

In your index.php file for your Wordpress theme you want to find your post container div (or whatever markup wraps your entire post). In the class area of this post you want to add a space after the first class (assuming you have a first class) and use the following PHP:

What this PHP will do is check to see if the variable $post is set with the string “set” and if it is not set with that string then it will echo out the class “firstPost” and then set the variable. Once the variable has been set each post afterwards will not echo out that class. Thereby creating a unique class for your first post that you can style however you want.

May be a little sloppy for the PHP gurus reading this— but it works.

Whats Next?

  • Save to Delicious! Page saved 0 times

10 Responses to “Styling the first post of your Wordpress blog”

  1. elena says:

    thanks a lot that helped me how to style only the first post of the blog in Wordpress. nice site

  2. jeeremie says:

    Hi,

    This solution didn’t work for me. Instead, I use this one »

  3. good point you have in there! thanks for sharing with us

  4. [...] the rest of Styling the first post of your Wordpress blog (191 [...]

  5. Steven says:

    Hi, when I put the code after the .post you will see at my page each post is named firstPost. I use wordpress 2.7, can some one help me?

  6. kamal says:

    hi, i dont see the PHP script, i use FF, and IE7!!!

  7. Thanks Dustin. This is a great informative post. I’m gonna follow your advice right now.

  8. InwaxinK says:

    Опутеть как интересно, во задвигаете. Класс!

  9. ammerigader says:

    Hi there, If you don’t like topics with many links, just delete this topic.
    Thankyou.

Leave a Reply


About Dustin Brewer

Dustin Brewer

Dustin Brewer is a freelance web designer based out of Oklahoma City, OK passionate about web standards, and beautiful web design. Dustin Brewer has been in the web design industry for over 8 years through freelance and professional experience. If you are interested in hiring Dustin Brewer please visit the web design services page to find out more information. You can also checkout the web design portfolio.

Contact Information

Quick Request Form

Contact me about your web design project.

Form is not working due to php sendmail issues. Will be back soon. In the interim use the contact page to get in touch with me. Thanks.






© 2009 Dustin Brewer Design. All Rights Reserved.
723 N Hudson Suite 400, Oklahoma City, OK 73102