How do I create multiple custom-sized featured post images for WordPress to display on the homepage?

Posted by:

Wordpress 3 has this built right in.  All you have to do is declare the image sizes in your theme’s functions.php file like so:

if ( function_exists( ‘add_theme_support’ ) )
add_theme_support( ‘post-thumbnails’ );

if ( function_exists( ‘add_image_size’ ) ) {
add_image_size( ‘category-thumb’, 200, 200 );
add_image_size( ‘homepage-thumb’, 220, 180, true );

The first part enables post thumbnails and the second declares the image sizes you want.  If you add TRUE to the image size declaration it will hard crop the image.

Then in each post you can set the post thumbnail (featured image) in the the sidebar on the right side.  In your templates you will need to call the correct image eg: category-thumb in the correct place like so:

if ( has_post_thumbnail() ) the_post_thumbnail( ‘category-thumb’ );
You should also consider installing a thumbnail rebuilding plugin in case you ever decide to change the sizes of the thumbs.  Use…


Add a Comment