![]()
WordPress magazine style themes have been all the rage lately, and everyone seems to want some aspect of their WordPress blog to have a magazine-y look and feel.
So if you have been around blogosphere recently, you must have seen those cool image thumbnails with short excerpts displayed on many blog home pages.
Today I went around searching for the easiest post thumbnail method, and was surprised to see how unnecessarily complicated some of the code junkies make something as simple as adding image thumbnails to posts.
So I hunt around a bit more and came up with an easy as pie way to add pretty little thumbnails to a WordPress 2.5 powered blog.
What you need to know: You need to know how to copy and paste.
What you don’t need to know: You don’t need to know how to open Photoshop.
So let’s get started.
WordPress 2.5 has a very handy new feature. It lets you specify custom thumbnail size for your uploaded images.
To adjust the thumbnail size to your liking, go to Settings > Miscellaneous and change the thumbnail width and height under Image sizes section. Let’s set the width and height to 80×80 for this example.
Also, make sure the Crop to size option is selected, and confirm the changes.
(With Crop to size checked, you don’t have to worry about what size your original image is. It will be adjusted to fit your specified size)
We want our thumbnail to be aligned to the left while the text flows around it. To do so, add the following code to your style.css file:
.thumb {float: left;margin-right: 7px;margin-bottom: 7px;}(Feel free to change or add to the code)
Next, we need to modify some code in index.php to correctly display the post thumbnails.
In your index.php, locate the part that is responsible for displaying your post content. It must be the following line or something similar to this depending on which theme you are using:
<?php the_content(); ?>Replace it with the following snippet:
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img src="<?php $values = get_post_custom_values("thumb"); echo $values[0]; ?>" alt="<?php the_title(); ?>" class="thumb" /></a><?php the_excerpt(); ?>(This code snippet retrieves the custom field value that we’ll add in the next step)
Now that everything else is done, it’s time to add the image.
Done! Write the post as usual, and don’t forget to enter a few lines in the excerpt field to be shown next the thumbnail.
Do you want to display regular content in case there’s no thumbnail image? No worries. David has come up with a code snippet that does just that for you.
<?php$thumb = get_post_meta($post->ID, "thumb", true);if ($thumb != ""){ ?><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img src="<?php $values = get_post_custom_values("thumb"); echo$values[0]; ?>" alt="<?php the_title(); ?>" class="thumb" /></a><?php the_excerpt(); ?><?php } else { ?><?php the_content(); ?><?php } ?>Read on David’s post for more detail.
If I missed an important detail, or if you know of a better, easier way to add thumbnails to posts, let me know about it in the comments.
Steal the spotlight with Spotlight WordPress Theme!
Spotlight is a robust Premium WordPress Theme. A product of my own tried and tested design and usability techniques.
Spotlight is WordPress 2.7 ready, and comes search engine, social media, and ad optimized, has paginated pages, paginated and threaded comments, featured post slideshow, a featured video bar, a full-fledged options panel, a ad management panel, and much more.
Thanks for sharing the tip – if you’re looking to make the thumbnails a regular feature, you might as well go with a magazine theme IMHO.
Also, adding a more quick-tag just below the image also helps in giving a thumbnail like effect.
Karthik, sure there is no dearth of WordPress magazine themes, but if someone is looking to pimp up their old theme, they’ll have do it manually.
Hm, I didn’t even notice this feature in 2.5. No more late night surfing for me…
I use Post-thumb revisited plugin (http://www.alakhnor.com/post-thumb/) to display thumbnails in 2.3.3. Quite good because it will automatically generate a small thumbnail of the first image in your post based on your configuration.
Jeremy, the first thing I did on WP 2.5 was explore the settings and hunt for new features. Almost all ideas voted by WordPress community including one click plugin updates and thumbnail resizing are there in the form of new features.
Kevin, thanks, I’ll have a look at the plugin. Though, are you sure this plugin gives you as much control over thumbnails as the manual method?
I have upgraded my blog to the latest WP 2.5 and yes it has far more useful features than the previous 2.3.3. I think I’m going to use your method for showing thumbnails.
But what do I need to add in the code snippet if I don’t want to show the thumbnail particularly in that post?
Great tutorial, I’ll implement something using this feature as soon as the maintainers of the plugins I use update their code to suit WP 2.5!
I’m in the process of creating a theme from scratch for a client and was looking for a simple way to create thumbnails on the index page as he didn’t want other bells and whistles that entailed a magazine-like theme.
I take what I said earlier back, this is an awesome method that is so simple and effective – thanks!
Just a pointer though – the Image Sizes section is under Miscellaneous and not Writing, not sure if it was changed when WP 2.5 became stable or not.
I’m just going to test it out, will let you guys know how it went, I’m sure its going to work like a charm!
Kevin, not sure about this because the custom field data is called directly from the index file so it doesn’t leave any room for overriding the code for individual posts.
You could omit uploading the thumbnail image for a particular post, but it would still leave an empty square where the thumbnail would have been.
Though you could write a conditional statement like this to tell the WP to show nothing in case the ‘thumb’ custom field is empty:
if (image exists) {
show image
} else (show nothing)
You can convert this pseudo-code into real PHP code, but I’m sorry I can’t be of any help here. My knowledge of PHP is next to nothing.
Copes, I’m glad you like it.
Karthik, Do let us know if it works for you.
Yes, it seems they have changed the location of resizing options in the stable release. I’ve corrected it now. Thanks.
Kevin,
If you need more pointers regarding implementing it, please contact me at karthik at iamkarthik dot com as the comment box doesn’t accomodate html and php code.
Mohsin,
I totally love the theme – would you mind if I made a few changes to the theme to make it WP 2.5 compatible? On a similar note, was the avoidance to support tags a conscious decision (I plan to include it if it were an accidental omission) ?
Karthik, is it Blue Ecstasy you are talking about? If so, sure do whatever you want to do with it.
The thought of adding tags support crossed my mind once, but then I decided to keep it as basic as possible.
But I might add tags support in an update later.
I wanted to use this feature on a project, but only wanted to use thumbnails for posts on occasion.
Using your code I seemed to have pulled off a statement to check for the thumb, and if no thumb exists it defaults back to the original formatting.
I barely know PHP, but it works on my site, so take it for what’s worth, or feel free to fix it up.
ID, “thumb”, true);
if ($thumb != “”)
{ ?>
<a href=”" title=”">
<img src=”" alt=”" class=”thumb” />
Ok… So I guess code gets stripped in the comments.
Using this code above as a base, I added an argument to allow a bit more flexibilty. The argument checks if a thumb is assigned to the post, and if not, the original code is used instead of the thumbnail code as to avoid the empty placeholder for where the thumb should be.
Hope it helps!
http://www.widecastmarketing.com/thumbnail-for-your-wordpress-2.5-posts.html
I don’t use wordpress myself because it lacks advanced features that I want but inserting thumbnails into WP posts is something that I figured out how to do with WP when I tried it out. Its actually very easy.
Create a new post and on the editor page upload the image using the FILE upload feature below the WYSIWYG editor. Once the image is upload you are given a chance to display it as a thumbnail or full sized image. After you select “thumbnail” you click on “send to editor” and then it will display the thumbnail in your post. If you want to left align the image you can add a custom css div using the code view of the editor.
Or you could use serendipity (www.s9y.org) and you’ll get a full featured media manager and the ability to upload and insert right, left or center aligned thumbnails/full sized images straight out of the box
.
Thanks, David. That works!
does it work in any themes ?
Great post. Thanks for this wonderful tutorial.
abdussamad, well that’s obvious, but we are talking about displaying post thumbnails only on the home page.
Bill, there is no reason why it shouldn’t!
Thank for your tip.
Thumbnail works great but it has made the text drop below. http://www.onlythegames.com how do I fix this?
Erik, it has something to do with the theme you are using. Try clearing the float and see if it fixes it.
Hi,
Firstly thanks for this excellent article… I have been searching for something like this for ages.
What I want to do basically is have a list of posts with thumbnails from a single category (like in your example) display in my sidebar. Do you know If I would be able to do this with this code? I’ve been searching for ages for some way to do this, and like you mentioned I found post thumbs revisited just way too complicated for my needs. I havnt been able to find any other plugins etc ,or ways to do this..
Many Thanks
Martin
Martin, try this code and let me know if it works for you.
<?php query_posts('cat=4'); ?><?php while (have_posts()) : the_post(); ?><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img src="<?php $values = get_post_custom_values("thumb"); echo $values[0]; ?>" alt="<?php the_title(); ?>" class="thumb" /></a><?php endwhile; ?>Change
catid to your desired category.Thank you for this post. I was a little lost trying to add thumbnails with WordPress 2.5. In WordPress 2.3.3 my thumbnails were by default being sized proportionately. With your post, I learned that the default thumbnail size in the WordPress Upgrade is set to a standard 150*150. All I had to do was deselect the fixed size setting to get back to what I’m used to from 2.3.3. I’m glad to have come across your blog. I’ve added it to my Feed. Thanks.
I still don’t like the limitations of WP thumbnails. You only get two options. I found the Viva plugin from meditricks works great for magazine style themes. It’s a paid plugin but was worth the few bucks as Tim and the guys helped me set it up and there support Rocks! What I love is the way I can add multiple styles of thumbnail to my homepage just by uploading with a post. Seriously worth checking out if, like me, you are playing with a move to a more magazine style theme. (Link is http://www.mediatricks.biz/demo) Tell ‘em I sent you – you might get discount!
Thanks a million, I modified it a little to suit my needs and it works perfectly.
This wordpress modifying is getting easier by the day thanks to great sites like this.
Hey, I was just about to write something kind of similar to what David’s update showed, so was looking around for how other people did it, and arrived here. My question is about your use of
Why is the thumb variable not used? How does get_post_custom_values differ?
Alex
Oops, that should have been as line 6 to 7 of the update
Alex, that’s because this particular part was copied as is from the original code of mine.
If you have any questions regarding David’s code, please post them on David’s blog as he’ll be better able to explain what he’s done.
Thank you, thank you! That took all of five minutes (and here I thought it would take all night!)
this is a great solution.
any idea how it can be used to display thumbs as related posts? (Post-thumb revisited plugin doesn’t work for me).
letrodectus, I really think it’s possible to achieve this functionality by modifying an existing related-posts plugin, but since I’m not a coder, I’ve no clue how to do it. You may want to contact a WordPress Plugin coder and request him to do that for you.
hmmmm i tried it last time with 2.5 and working smoothly but after upgrading to 2.5.1 it doesnt work
Would not resize the img. everything else worked fine.
Great stuff, this is just what i was looking for.
Sorry, but I could not get it working properly. I am getting the full size images even after doing all those steps. Can you help me through it?
Ok I got it right. I was doing some thing wrong. Thank you very much for this tutorial
Great! As soon as I get back from holiday, I’m going to try this.
I was looking for such a feature for quite a long time, I want to use it for my current theme.
Thanks a lot!
Great post thank you so much for a simple yet very effective addon! This was exactly what I was looking for, I couldnt find it anywhere!
I am a newbie just setting my wordpress blog. I must say the steps gave me a good highlight how it works, specially step 4 is all I needed.
Thank you for this post. I’ve been looking for a way to display the thumbnail size image on the home page, and the full size image on the post page. I think this will allow me to do that
bocdomva
Thank you for your website
I made with photoshop backgrounds for myspace and youtube and ect..
my backgrounds:http://tinyurl.com/6r7cav
all the best and thank you again!
How I cant show readmore link for excerpt???
Thanks for the snippet! I am using it in my site now. Thanks a lot!
Is it possible to use this to have a page of thumbnails for a category? I have a client who wants to put up thumbnails for her posts on the category pages rather than (or possibly in addition to) the regular archive of posts for that category.
THANK YOU THANK YOU!!!
i searched all day yesterday for a plug in or a easy way to do this… and this made it the most simple to understand i cant understand why this would be so hard… but you made it understandable…
question… is there a way to make a category page look like the home page…
for instance if i click on a category link like “events” i want it to show thumbnail view before going into the details… right now it lists all the posts with full detail…and no excerpt or read more…
please help
no worries i got it just had to add the same code to the archive.php file..
thanks
It ain’t working for me.
Its not working. The thumbnail isn’t resizing into the size that I have entered. Any idea?
Sehr Gut, vielen Dank !!!
Thank you for posting these instructions! =)
(Going to use it to display “latest products” in the sidebar of my blogshop with eShop! )
Image will not auto resize in 2.6.5. Any advise?
Hi there,
Firstly I want to say how good this is and just what I was looking for.
I, however, am having a few problems with it which I am sure is my fault.
Let me show you links rather than try to explain. I want to have the thumbnails appearing on this page, the category page. In this instance it is Lifestyle>Technology.
http://www.ionoxfordtube.com/wordpress/category/lifestyle/technology/
Instead, it still shows the full posts and not the thumbnail. When you click on the article title, it takes you to the article, but then shows you the thumbnail and the [...] but not the whole article:
http://www.ionoxfordtube.com/wordpress/11/2008/more-mivlos-by-oli-mival/
I am sure I am doing something wrong, but can’t work out what… I am a relative newcomer to WP so that’s probably why I am struggling with this.
Hopefully you can shed some light on it. The Oli Mival article in Technology is the only one I have so far tried this on.
Thanks
Ben
Ben H, are you sure you added the code in ‘category.php’? (or it may be archive.php depending on the theme you’re using).
It looks to me that you have added the code snippet to ’single.php’ instead. Check this and let me know.
Hi there. Thanks for the reply.
You are right, I did put it in the wrong file, but when I look in category.php, doesn’t even exist…
I trust this is category.php that resides in wp-includes?
I am using Blue Zinfandel.
Thanks for your help.
Ben
Hi again.
I changed archive.php and it has worked on the category page but now the article itself has no text, just the title.
Sorry about this, I am sure it is my lack of knowledge.
Thanks for your help though!
Ben
All sorted.
Thanks for your help, I found it. I had commented out in index.php and forgot to uncomment it.
Many thanks for this article. You saved me a lot of time!!
Cheers
Ben
Well. at last I may have found a site that could help me with my Wordpress problem.
Although I have made a few websites over the last few years using Frontpage, I have just had a go at doing my first blog.
I did like the Caffeinated Content concept and have incorporated this in my Wordpress blog. Problem is I don’t know how to display images which are automatically uploaded through the Caffeinated Content. I have added a plugin called Post Thumb and followed the directions given on this site, but I still can’t get the images to display.
Can someone possibly give a step-by-step procedure on how to display my images – without getting too technical for my lack of html knowledge.
thanks for this info…
Hi,
Thankkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk you!!!
@Mohsin,
Thank you for the tip, I think this would be more manageable than using plugins.
I’m currently trying to implement it manually on a site that I’m testing (http://www.samsungi907.com/careace/). As you can see, the title is all jumbled up with the post meta and image. Is this a result of only one post being implemented, or is there another reason for it?
Here’s my code for the index portion:
`
<a href=”" rel=”bookmark”>
<img src=”" alt=”" class=”thumb” />
<?php the_excerpt((’Read More…‘));?>
<a href=”"> on
<?php comments_popup_link(__(’Comments (0)‘), __(’Comments (1)‘), __(’Comments (%)‘)); ?>
<?php edit_post_link(__(’Edit This Post’)); ?>
`
Usefull informations. Thank you
In step “2″ you make changes to the .css file.
Where in the code do you make the changes? I’m using 2.7 church theme.
Thanks, Nicole
Stone, just add the changes to the bottom of the CSS file and you’re done.
Thank you Mohsin, I’ll do that.
Thanks a million for this! I’m new to blogging and I’ve been fiddling around with this only to be met with frustration!
First sorry for my bad english.
Thank you for this interesting post wich help me a lot.
My only problem is the bad quality of the thambnail.
someone want to help for generting good thambnail quality
thanks in advance
Great tutorial! This is simple and effective. I don’t think one needs a plugin. Developers say less plugins better, so that the site doesn’t run slow, and well this tutorial is so simple for everyday use, it isn’t a lot more work.
THANK YOU! Bingo!
the_excerpt doesn’t work in 2.7.
What can I do?
Thanks for sharing this. I’ll look into my site to see how I can change the current format. I use a plug-in to view the thumbs.