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

Murphy - Home Maintenance & Repair Service HTML Template

Murphy is a handyman repair service Bootstrap HTML Template. It is ideal for either all-rounders or professional teams to introduce the...