Post Thumbnails

DescriptionWordpress snippet by - 03/23/10

You may have heard a bit of news about a new thumbnail/featured image for themes coming to WordPress 2.9. Yes, you'll be able to easily upload a post thumbnail. However, it's not just thumbnails. The image will have various sizes. So, I'm going to refer to this feature as the post image feature.

More InformationGoto Reference Page

Tags , ,

//add this to the functions.php file
add_theme_support( 'post-thumbnails' );

//add this to the functions.php file this to only add to page templates not posts
add_theme_support( 'post-thumbnails', array( 'page' ) );

//Show the thumbnail
<?php the_post_thumbnail( 'thumbnail' ); ?>

//Show the thumbnail as medium
<?php the_post_thumbnail( 'medium' ); ?>

//Change thumbnail size

if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'game-thumb', 100, 74 ,true);//true arg is for hard crop
}

//Use a conditional

<?php if ( has_post_thumbnail() ) the_post_thumbnail('game-thumb'); ?>

//Change the title attribute

<?php the_post_thumbnail( 'post-thumbnail', array( 'title' => $title, 'alt' => $title ) ); ?>
  • Share
Submitted by: Adam J Nowak
http://hyperspatial.com

Comments and Feedback