• Resolved glenncvance

    (@glenncvance)


    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!

Viewing 3 replies - 1 through 3 (of 3 total)
  • try:

    <?php if( get_the_post_thumbnail($post->ID) ) { ?>
    <div class="postthumb">
    <?php the_post_thumbnail(); ?></div>
    <?php } ?>
    <?php the_content(__('Read more'));?>
    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    if ( has_post_thumbnail() ) {
    ...
    }
    Thread Starter glenncvance

    (@glenncvance)

    And that is why I LOVE the forums here! I’ve been working with WP for several years but if I ever can’t figure something out someone on the forums usually has the answer.

    alchymyth – Worked like a charm! My posts with thumbs show properly AND my posts without thumbs don’t have the border anymore! Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Don't Show a Featured Image When There is No Featured Image’ is closed to new replies.