Custom post thumbnails

Wpsnipp – Thumbnail is an image that is chosen as the representative image for Posts, Pages or Custom Post Types. The display of this images is up to the theme. This is especially useful for “magazine-style” themes where each post has an image. Adding this PHP code to your wordpress theme will allow you to define a post thumbnail. Create a custom field called post-img and add a URL to your image.

 

 

<?php
$postimageurl = get_post_meta($post->ID, 'post-img', true);
if ($postimageurl) {
?>
<a href="<?php the_permalink(); ?>" rel="bookmark"><img src="<?php echo $postimageurl; ?>" alt="<?php the_title(); ?>" width="210" height="210" /></a>
<?php } else { ?>
<a href="<?php the_permalink(); ?>" rel="bookmark"><img src="<?php bloginfo('template_url'); ?>/images/wpbeginner.gif" alt="<?php the_title(); ?>" width="210" height="210" /></a>
<?php } ?>

Be Sociable, Share!

Leave a comment