Using featured images in WordPress is one of the newest and most robust features of 3.0.

To use featured images in a post you must first append you functions.php file with:

add_theme_support( 'post-thumbnails' );

This lets WordPress know you’re going to be using the featured images. You’ll then want to go to your posts page, click Screen Options in the upper right corner and verify ‘Featured Image’ has been added and is checked.

Next add the following snippet to your code where you want your featured image to show up:

Post_ID is optional but it’s the ID of the post you want to use as the source for your featured image. If you put nothing it defaults to the post currently being viewed.

Size is either a string keyword (thumbnail, medium, large or full) or a 2-item array representing width and height in pixels, e.g. array(32,32).

Attr relates to the array of other options. See the code snippet below.

$default_attr = array(
'src' => $src,
'class' => "attachment-$size",
'alt' => trim(strip_tags( $attachment->post_excerpt )),
'title' => trim(strip_tags( $attachment->post_title )),
);

Now that we’ve covered all that you could do something like below:

'alignleft')); ?>

You’re going to pull the featured image from post 4, display a thumbnail and assign it the class alignleft. Not to shabby, huh? For more information check out the Get the post thumbnail reference page on the Codex at:

http://codex.wordpress.org/FunctionReference/getthepostthumbnail

 

Looking for something?

Use the form below to search the site:


Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...