Thumbnails and Captions

The new ‘featured image’ facility on WordPress is really useful. It has to be enabled in your themes functions.php file with a couple of lines of code something like this:

Once it’s enabled you can add the image very easily anywhere in the loop usingĀ <?php the_post_thumbnail(); ?>.

Mark Jaquith has written a nice article explaining how you can set up different images sizes and there’s a very useful plugin calledĀ Multiple Post Thumbnails that allows the addition of multiple featured images.

It’s not obvious how you can add a caption to a featured image. The trick lies in calling the associated attachment post. You can show the image caption using the following code:

Similarly you can show the full description or the image title if you prefer:

You can add any classes you need in order to style the results.