Style Posts From Some Category Differently


Sponsored Links




Right now, every blogger has know WordPress as easiest and nicely support publishing system. To create more sophisticated and personal blog. Blogger chooses WordPress as they Blog Engine. Some featured that we can use to create more unique blog is style some category differently.

Style WordPress Category Differently - Cute Japan Girls

Style WordPress Category Differently - Cute Japan Girls

In WordPress do this tricks is quite simple, we only need added extra code and added CSS Style for this area. Example we will create different style on category 5 here the code. Put this code on your WordPress Loop or you can directly edit on your index.php

 <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
 <?php if ( in_category('5') ) { ?>
           <div class="post-cat-five">
 <?php } else { ?>
           <div class="post">
 <?php } ?>
 <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
 <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>
 <div class="entry">
   <?php the_content(); ?>
 </div>
 <p class="postmetadata">Posted in <?php the_category(', '); ?></p>
 </div>
 <?php endwhile; else: ?>
 <p>Sorry, no posts matched your criteria.</p>
 <?php endif; ?>

I will explain the code, on the code above we put some condition, if the loop find post in category 5 the div class name will be post-cat-five but and other class name will be post.

The next step is added CSS style on your style.css, here an example

.post-cat-five {
background: #efefef;
padding: 15px;
border: 1px solid #ccc;
}
.post {
border-bottom: 1px dotted #999;
}

That’s it, Now each post in Category 5 will be style differently. I hope today tutorial how Style Posts From Some Category Differently useful on you

Photos courtesy of Kanegen flickr account

Subscribe to Full RSS Feed

RSS FeedIf you thing this article useful, please consider subscribing to our RSS Feed or e-mail updates and stay updated with us. You can also follow @WPTricksNet on twitter for latest updates.

About WP Tricks

We are WordPress Family, we collected and writed useful tips and tricks for you WordPress. We share it for you...

Related Tips and Trick from Local Data and on The Net


One Response to Style Posts From Some Category Differently

  1. Pingback: wp-popular.com » Blog Archive » Style Posts From Some Category Differently # WordPress Tricks & Tips

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>