{theblog}The Blog

Post Thumbnails via WordPress

Posted on 03/01/10 | Category: blog, development | Tags: , , ,

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.

The Function

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
>

Placing the Thumbnail

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.

Uploading the Thumbnail

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

TwitterFacebookStumbleUponDiggDeliciousRedditGoogleTechnorati
About the author
Phil Splice is a growing designer. After a few years history of C++, he decided to move over to the design side of programming. Phil currently designs with TLR Design and runs his own blog at philocity.com.

Related Posts You Might Like

4 Comments

  1. 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/

  2. Saad Ibrahim says:

    quite a useful trick there! thanks!

  3. Great post Phil! You make it sound too easy!

  4. Tyler says:

    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?

Leave a Reply




Copyright © 2010 Amber Weinberg. All rights Reserved. Please don't steal, it's really not cool! But if you'd love to work with me (you do don't you?), please contact me :)