wordpress different post styles

After wordpress 2.7 new function post_class() is added which helps theme authors to apply different styles to wordpress posts.

To use this function you have to add this function in the wordpress loop. on older themes they have added class=”post” to the

in wordpress loops instead of that just add post_class().

<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

It can add the following classes which you can use as a hook for CSS-styling:

* .post-id
* .post (or .page or .attachment, depending on the post type)
* .sticky
* .hentry
* .category-misc
* .category-example
* .tag-news
* .tag-wordpress
* .tag-markup

using .category-example you can apply different styles to posts. so if you want to style post within specials category you can simply achieve this by applying style using

.category-specials
{
/*Your style here*/
}

So using this you can apply different styles to different categories.

Similarly if you want to style sticky posts you can achieve this by using

.sticky 
{
/*Your style here*/
}

Leave a Reply

Your email address will not be published. Required fields are marked *

One Comment

  1. hi excellent website with cool tutorials and collection of codes