Don't Show a Featured Image When There is No Featured Image
-
Hi there – I’m trying to update an old theme that I’ve used in the past on my site and I’ve gotten into a bit of a conundrum – I want to show featured images with my posts, but if there is no featured image I don’t want my theme thinking there should be one and showing some space with title tags and a border that’s it.
Currently I’m using this code in my functions.php –
// Add support for Featured Images if (function_exists('add_theme_support')) { add_theme_support('post-thumbnails'); }
And I’m using this in my loop –
<div class="postthumb"> <?php the_post_thumbnail(); ?></div> <?php the_content(__('Read more'));?>
And it does show a thumbnail, which was my goal. I’m also using this styling for the div –
.postthumb{float:left; width:auto; border:1px solid #777;margin:0 20px 10px 0}
And that makes the thumbnail nice and have a border and all of that, but if I don’t add a featured image then I still get a tiny border around…nothing.
What could I add to the
<?php the_post_thumbnail(); ?>
statement to accomplish that and not have the tiny border?Thanks in advance!
- The topic ‘Don't Show a Featured Image When There is No Featured Image’ is closed to new replies.