Activating the Post Thumbnail feature in Wordpress but not showing anything if there is no image to display

/ Published in: PHP
Save to your folder(s)

I looked everywhere trying to find some code that could show me how to display the post thumbnail if there is an image, but to display absolutely nothing if there isn't an image to display (most just either added an image or there was a broken image if there was nothing to display).

Copy this code and paste it in your HTML
  1. <?php if (get_post_meta($post->ID, 'post-image', true) != "" ) : ?>
  2. <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="borderimg">
  3. <?php $thumbnail_image = get_post_meta($post->ID, 'post-image', true);?>
  4. <img src="<?php bloginfo('template_url'); ?>/scripts/timthumb.php?src=<?php echo $thumbnail_image; ?>&amp;h=141&amp;w=200&amp;zc=1" alt="" />
  5. </a>
  6. <?php endif; ?>

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.