Use WP template post-class() to style posts individually
We have so many posts in different categories or tags. Sometimes we may need to provide some special CSS style layout to some named posts, categories or tags. If that’s what you want to achieve, the wordpress template function post-class() can help.
To use this function in a theme, you will simply add it to the Loop in a place that makes sense. Most themes encapsulate every post within a DIV of some sort. That DIV usually has a class=”post” or something similar. Instead of that class, just add a call to post_class instead. Like so:
<div id=”post-<?php the_ID(); ?>” <?php post_class(); ?>>
The post_class() outputs the class=”whatever” piece for that div. This includes several different classes of value: post, hentry (for hAtom microformat pages), category-X (where X is the slug of every category the post is in), and tag-X (similar, but with tags). It also adds “sticky” for posts marked as sticky posts. These make it easy to style different parts of the theme in different ways. Read the Wordpress documents about post-class() here.
Wordpress 2.7 after versions provide the “stick post” feature, that is, for those posts you’ve published before , now you can place them at the top of your homepage without editing the timestamp, only by checking “stick this post to the front page” in WordPress post edit panel. Here this article explains in deep details on how to style a stick post.
In the same way, you can also give special styling to named categories or tags. Another tutorial talks more about it.
Post comment
Sponsored by
Recent Posts
- 52 Excellent Single Page Sites Inspiring For Designers
- Very Simple & Tiny Lightboxing: Lightbox_me
- 10+ Free HTML5-CSS3 Website Templates
- Bizarre Websites On Which You Can Kill Time With Style
- 40 Beautiful E-Commerce Websites 2010
- gMap – google maps plugin for jquery
- Contextual Slideout Tips With jQuery & CSS3
- TipTip jQuery Plugin
- Showcase Of Beautiful Vertical Navigation Designs
- 45+ Fresh Wordpress Tutorials, Techniques and Hacks
Tag Cloud
Archives
- June 2010 (4)
- May 2010 (1)
- April 2010 (8)
- March 2010 (24)
- February 2010 (10)
- January 2010 (16)
- December 2009 (25)

admin




