Bootstrap Templates Bundle

Thursday, February 28, 2013

Setting default post image for different categories

If no image is attach to the post then rhis code will help us to show different post image for different categories


<?php if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())) : ?>

<?php the_post_thumbnail('thumbnail'); ?>

<?php else :?>

<img src="<?php bloginfo('template_directory'); ?>/category/<?php $category = get_the_category(); echo $category[0]->cat_name; ?>.jpg" />

<?php endif;?>
</div>



make a folder category by name in your theme directory. then add some image for your every category. such as news.jpg,  uncategorized.jpg etc

No comments:

Post a Comment

Nightery - Night Club WordPress Theme

Nightery - Night Club WordPress Theme Nightery – Night Club WordPress Theme is an awesome design idea for your Night Club, Conce...