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
<?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