I’ve been playing around with the Twenty Ten theme, which incorporates a wonderful feature called Featured Images. Those have actually been around since 2.9 (where they were called “thumbnails”), but I’ve never gotten around to exploring them. Mark Jaquith explains all about thumbnails / featured images, but here’s the bottom line: FI’s are just like any other attachment, except a given post or page has at most one. Thus they can be used to visually represent that post in archives and search pages (as a thumbnail), or displayed in the post itself (full size), in any number of ways—inserted in the post body, for example, or maybe used as a custom header image like Twenty Ten does. I’m sure there are a million other options.
And all without mucking about with custom fields! All you need to enable this feature is to add three lines to your functions.php file:
add_theme_support( 'post-thumbnails' ); set_post_thumbnail_size( 50, 50, true ); add_image_size( 'single-post-thumbnail', 400, 9999 )
The second and third lines set the dimensions for the image either as a thumbnail, or in the single post. From doing a bit of experimenting, it looks like only the first two are required. As the name implies, add_image_size()
registers different image sizes, to be used in different contexts: search pages, main page, what have you. set_post_thumbnail_size()
‘s third, optional, argument (and add_image_size()
fourth argument) determine whether or not the image is hard-cropped (by default, it is not). WordPress’s editor UI lets you determine the cropping for images that don’t fit the preset proportions, easy as pie.
Note that the switch in terminology from “thumbnail” to “featured image” only happened in the last few months, and is still ongoing even in the official documentation.
This is a wonderfully easy-to-use, yet very versatile, feature; I’m working on a project for which it’ll be absolutely perfect. Stay tuned…