Home » Labs » Custom post thumbnails to WordPress posts  

Custom post thumbnails to WordPress posts


Filed under Labs

You can define a custom post thumbnail by adding following code to your WP theme. For this you need to create a custom field called post-img 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="150" height="150" /></a>
	<?php } else { ?>
	<a href="<?php the_permalink(); ?>" rel="bookmark"><img src="<?php bloginfo('template_url'); ?>/images/my-default-img.png" alt="<?php the_title(); ?>" width="210" height="210" /></a>
	<?php } ?>
It's only fair to share...Share on Google+Tweet about this on TwitterShare on Facebook

Posts you may like: