June 24, 2010

WordPress post thumbnails

by Karine in Wordpress with no response

Since version 2.9, WordPress allows post thumbnails! You can set a different thumbnail size from your WordPress media settings too. Open your theme functions.php file, or, if you don't have one, create it. Paste this code :

if ( function_exists( 'add_image_size' ) ) add_theme_support( 'post-thumbnails' );
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'home-thumb', 300, 200 ); // duplicate this line to add more sizes
}

home-thumb is the name of your custom thumbnail size. If you want to add more sizes, duplicate the line and change the values.
300 and 200 are your custom thumbnail width and height. Change the value to whatever you want.

Now, we want to display posts thumbnails in our theme. Paste this code where you want the thumbnail to appear:

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

Hmm, still seeing nothing? Maybe that's because you haven't set a featured image in your post! Edit your posts and click "Set featured image", choose an image and you're done.

Wordpress set featured image

Tags

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.

↑ Back to Top