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:
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:
Comments are closed.
- A Wandering Mind
- And the Shutter says Click
- Baby Poop
- Behind the Scenes
- Coffee Has It's Perks
- Design Schmesign
- Destination Unknown
- From the Blogosphere
- From the Web
- I Don't Like Spam
- In the News
- It's a Mac Mac Mac Mac World
- It's Code and That's All There is To It
- It's not a family circus it's a zoo
- OMG I'm a Parent
- On the Tube
- Scientific Notation
- Sunday Funnies
- Teach me, Seymour! Teach Me!
- That's Life
- The 20 Second Look Away
- The Home Front
- Weird Wired World
- You Gotta Laugh