Using Custom Fields for post thumbnail – WordPress

There are couple of ways you can show thumbnail of a post in your WordPress blog.

First thing you need to do is create a custom field under add post section with any name you wish, but let’s say you name it as “Thumbnail”.

Now in the value put the image location (http://www.example.com/imageFolder/thumbnail.jpg). So now you have what you need to show thumbnail for your post.

Do this in you page where you wish to show posts and their thumbnail:

$img = get_post_custom_values("Thumbnail");
if($img[0]){
	echo "<img src='$img[0]' height='75' width='75' alt='$post->post_title'  />
                $post->post_title";
}

You can show multiple posts with thumbnail. We will take my earlier post as reference http://www.yoursearchbuddy.com/post-category-wordpress :

<table>
	<?php $recent = new WP_Query("cat=categoryId&showposts=numberOfPost");
	      while($recent->have_posts()) : $recent->the_post();
	?>
		<tr>
			<?php
				$img = get_post_custom_values("Thumbnail");
				if($img[0]){
					echo "<td><img src='$img[0]'  alt='$post->post_title'
						  title='$post->post_title' /></td>";
				}
			?>
			<td>
				<a href="<?php the_permalink() ?>" rel="bookmark">
					<?php the_title(); ?>
				</a>
			</td>
		</tr>
		<?php endwhile; ?>
</table>
Tags: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*