Specific featured image for each category

<?php
if(has_post_thumbnail())
    the_post_thumbnail('themolio-featured-image');
else
    echo wp_get_attachment_image($attachment_id, 'themolio-featured-image');
?>

The above code displays the featured image if the post has one, otherwise the image define by $attachment_id.

I don’t know how you’re deciding which category term should display which image & what to do in case of multiple categories, so the part where you initialize $attachment_id is left to you.

UPDATE

This code does exactly what you said in your comment. In case of multiple categories, this code will just take the first one.

<?php
$category = get_the_category();
if(!empty($category) && $themolio_options['show_featured']): ?>
<div class="entry-thumb">
    <a href="https://wordpress.stackexchange.com/questions/75455/<?php the_permalink(); ?>">
    <img src="http://example.com/<?php echo $category[0]->term_id;?>.jpg" alt="<?php echo $category[0]->name;?>" />
    </a>
</div>
<?php endif; ?>

Leave a Comment