How To Style 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.

Comments

About the author:
Dustin Brewer is a web designer located in Oklahoma City, OK specializing in aesthetics in design, web standards, accessibility and usability. He also enjoys helping others to discover CSS and web design best practices through his web site, dustin brewer, a web design news site.

About The Author

Dustin Brewer is a web designer located in Oklahoma City, OK specializing in aesthetics in design, web standards, accessibility and usability. He also enjoys helping others to discover CSS and web design best practices through his web site, dustin brewer, a web design news site.

Posted in: Blogging, The Net |
Stumble Digg Technorati Subscribe Delicious
del.icio.us Digg Reddit Netscape StumbleUpon Technorati

If you enjoyed this post, then make sure you subscribe to my RSS Feed.
 

Related Posts

RSS feed | Trackback URI

1 Comment »

Comment by Sandy Fox

June 18th, 2008 at 1:20 pm

That’s a pretty cool technique but you can avoid a lot of hassle by using a plug-in. I believe it is called “Sticky Post”, or something to that effect. You can make specific posts appear as #1 depending on the page and/or category. Like many plug-ins it is not perfect but it’ll definitely get the job done.

Hope this helps!

 
Name (required)
E-mail (required - never shown publicly)
Website
Subscribe to comments via email
Your Comment (smaller size | larger size)