This tip is for all themes that support WordPress' Post Thumbnails (also known as Featured Images). If you're using Thesis, this does not apply to you since Thesis uses its own Post Image solution.
In version 2.9 WordPress added support for Post Thumbnails, which allowed you to upload an image using the standard uploader, and select it as the image that represents the post. This image could then be used throughout the site in thumbnails of different sizes, and displayed on the post itself.
Mark Jaquith provides an excellent summary of WordPress Post Thumbnails , so I'm not going to repeat it.
I'm building a client's site with Genesis and using this feature. One issue that came up was Captions. The WordPress uploader let's you specify a caption for an image, but when you use the_post_thumbnail() it just displays the image.
I couldn't find any documentation on retrieving the image's caption, so I asked Mark. I thought it would be useful to share it.
WordPress stores images as their own post, and it stores the caption as the post's excerpt. To display the image and it's caption, use this:
The first line creates a div called "featured image" so that we can style it later with CSS. The second line displays the post image. The third line uses get_post() to get the "featured image" post and pull out the excerpt, which is where the caption is stored. We then wrap it in a span with a class of "caption" for styling. Finally we close the original div.
To get the description instead of caption, use post_content instead of post_excerpt.
No comments yet