Different fallback image per category

Posted in: Newspaper
Post count: 101

Our site is divided into mainly music, film and books. Since some posts have no set featured image, we want to set a fallback image per category.

Nearly all of the time we make use of flex block 1, and doing a search online I found a code which would do the trick

<?php if ( has_post_thumbnail() ) : ?>

<div class="entry-thumbnail">
"><?php the_post_thumbnail(); ?>
</div>

<?php else :
$category = get_the_category();
?>
<div class="entry-thumbnail">
">/wp-content/uploads/category-images/<?php echo $category[0]->category_nicename ; ?>-150x150.jpg" alt="<?php the_title(); ?>" />
</div>

<?php endif; ?>

Can anyone of you suggest if this can be implemented manually ?

Looking at the flex block code I figure I would make some changes here on line 22:
if (empty($image_size)) {
$image_size = 'td_696x0';
}

Post count: 20685

Hi,

Indeed, if there is no featured image set the them will display a placeholder image (no thumb)
https://www.screencast.com/t/d4iMZ0PoTy
But this will not take categories into account, maybe if you create conditions and also additional images
https://www.screencast.com/t/S7yh3Q2gvuaa
I believe this may not be easy.

By default it would be simple, if the post has no thumb, module loads a no thumb placeholder of the appropriate size.

Some users that installed the theme and had multiple old posts with no featured image, reported that they used a plugin (auto post thumbnail I think) to automatically use the first image found in the post content as featured.

However I don’t know if that plugin works or not with the theme properly, just thought of mentioning it.

Thanks

Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic.