How to handle thumbnails

Since WordPress 2.9, you can add thumbnail support to your theme by adding this to the theme’s functions.php file:

if ( function_exists( 'add_theme_support' ) ) { 
  add_theme_support( 'post-thumbnails' ); 
}

When this is done, you’ll be able to add a feature image to your post on Posts, Pages or Custom Post Types. You’ll see the “Featured Image” box when creating a new post.

You can set the thumbnail size also in your functions.php file. You can use WordPress’ “thumbnail”, “medium” and “large” sizes, create your own or specify a size with pixels:

the_post_thumbnail('thumbnail');       // Thumbnail (default 150px x 150px max)
the_post_thumbnail('medium');          // Medium resolution (default 300px x 300px max)
the_post_thumbnail('large');           // Large resolution (default 640px x 640px max)

the_post_thumbnail( array(100,100) );  // Specify resolution
//Add your own:
add_image_size( 'category-thumb', 300, 9999 ); //300 pixels wide (and unlimited height)

Example of how to use this new Post Thumbnail size in theme template files.

<?php the_post_thumbnail( 'category-thumb' ); ?>

You should check Codex’s page on Post Thumbnails for more info. There you’ll also find how to style your thumbnails and more details on this code.

Leave a Comment