Adding Featured Thumbnail Images To A WordPress Template

I have had a couple questions recently about Featured thumbnails and adding them to your WordPress templates. This is infact a very easy thing to do, so I will make this a quick post, and of course if you have anymore questions please leave a comment and I will address them!

So, your Featured Image is going to be added to your archive/category lists as well as your excerpt.  But what if you want to add your Featured Image into your post or page?

To do this go into your theme directory and find the single.php and page.php (if you need more information about building custom templates see Adding Custom Widgets and Page Templates with WordPress).

In the single.php file look for:

<?php the_content(); ?>

To add your Featured Image add

<?php the_post_thumbnail(); ?>

Save the file and go back to your site, refresh your post to see the Thumbnail Image show up!  That’s the basics, here are a few more useful things that can really help make it useful for you:

<?php the_post_thumbnail('thumbnail'); ?> // thumbnail size 
<?php the_post_thumbnail('medium'); ?> // medium size 
<?php the_post_thumbnail('large'); ?> // large size

To use your own thumbnail dimensions:

<?php the_post_thumbnail(array( 200,200 ); ?>

Finally, if you would like to add a little CSS styling (‘alignleft’ being the new css class)

<?php the_post_thumbnail(array( 200,200 ), array( 'class' => 'alignleft' )); ?>

Hope this has been useful!

No Responses

ADD YOUR COMMENT