It allows you to have a default feature image for a category on a wordpress post. So I’ve got categories called ‘Dogs’ and ‘Cats’ and this code allows the default feature image for any post in these categories to have a picture of an Dog or a Cat. I’ve also used it on the ‘uncategorised’ category, so they all have a basic placeholder thumbnail.
1 2 3 4 5 6 7 8 9 10 11 |
<?php if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail())) : ?> <?php the_post_thumbnail('thumbnail'); ?> <?php else :?> <img src="<?php bloginfo('template_directory'); ?>/images/<?php $category = get_the_category(); echo $category[0]->cat_name; ?>.png" /> <?php endif;?> |
Added By Dan