
Images are more appealing than text alone so, wouldn’t it be nice to upload and place a thumbnail next to the post?
It’s very simple with WordPress 2.9+, all you need is a few lines of code in your functions.php. So, therefore we need to open functions.php as well as index.php.
In your functions.php place this code and tweak as necessary:
<php add_theme_support( 'post-thumbnails', array( 'post' ) ); //displays thumbnail for only posts set_post_thumbnail_size( 50, 50, true ); //50 pixels wide by 50 pixels long, box resize mode >
Wherever you would like the thumbnail to appear place this code:
<php if ( has_post_thumbnail() ) echo the_post_thumbnail(); else { echo '<img src="http://yourdomain.com/default.png" />'; } >
This tells WordPress that if this post has a thumbnail uploaded (we will get to that in a moment), display it; otherwise display the default image.
How do you upload a thumbnail? When adding a new post, under categories look for “Post Thumbnail” and click “Set thumbnail”.
Of course, this can be styled and tweaked to your needs so have fun tweaking and thanks for reading!
Image by by David Reeves
Good article, thumbnails are easy in WP2.9 and this shows it. I might also recommend an article Matt Brett did recently on this subject: http://mattbrett.com/2010/01/bulletproof-post-thumbnails-in-wordpress-2-9/
quite a useful trick there! thanks!
Great post Phil! You make it sound too easy!
Yes, you don’t need all of this, it’s much easier in WP 2.9 and why would you be using anything other than the latest?