This is a quick tutorial on how to use the new the_post_thumbnail function in Wordpress 2.9 to create a Featured section on your website. You’ll find this useful if you want to display one “featured” post at the top of your page at a time.
Add the following to the functions.php file in your theme:
if ( function_exists( ‘add_theme_support’ ) )
add_theme_support( ‘post-thumbnails’ );
This enables the_post_thumbnail for your theme.
Through the Wordpress backend, create a new category called Featured. Note the number that corresponds with your new category by going to your Categories section, hovering over Featured, and noting it’s cat_ID which should appear at the bottom left corner of your browser (at least for Firefox and Chrome).
In a new PHP file, paste this code:
<?php query_posts(‘cat=XX&showposts=1′); ?>
<?php while (have_posts()) : the_post(); ?>
<a href=”<?php the_permalink() ?>” rel=”bookmark”>
<?php the_post_thumbnail(‘medium’); ?>
</a>
<a href=”<?php the_permalink() ?>” rel=”bookmark”><?php the_title(); ?></a>
<?php the_excerpt(); ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
Change XX to the number that corresponds with your featured category. Save the file to your theme’s main directory and name it “featured.php”.
Choose where you want to include your Featured section, perhaps at the top index.php file. Use <?php include(TEMPLATEPATH . ‘/featured.php’); ?> to include your featured.php file in your theme.
Voila! Your blog will now display the following on any post you create under your Featured category (completely unformatted, of course):
- The thumbnail you attach to the post
- The post title
- Post excerpt



[...] http://poplicola.com/using-the_post_thumbnail-with-wordpress-2-9/ [...]