![]()
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.
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.
Good plug in man.. hope it will be so help full for my site
thank you
vist : getmag.co.cc
Great job on the post! I am using the code on my blog right now (http://www.monkeybyte.net), and it works like a charm, esp. the snippet that you included from David.
I searched around on several other blogs for how to do this and yours was the most clear and concise. Again, great job man! This really is the best.
After reading this blog makes me want to start my own
Hi, Just like to tell you that this piece of info is one quick to the point, no nonsense, workable and effective way as fast as possible. It worked for me and thank you for the effort. Keep up the good work.
I dont really care one way or another. ,
I came up with a modified more automatic version. There is some stuff about it on my blog at bobdavis321 on blogspot. Basically It uses the built in thumbnail and automatically finds it from searching through the post for the first image.
here is the function code;
/* For Getting the Image FASTER */
//GET-POST-IMAGE1 quicker than the script by Tim McDaniels
function get_post_image1 ($post_id=0, $width=0, $height=0, $img_script=”) {
global $wpdb;
if($post_id > 0) {
$sql = ‘SELECT post_content FROM ‘ . $wpdb->posts . ‘ WHERE id = ‘ . $wpdb->escape($post_id);
$row = $wpdb->get_row($sql);
$the_content = $row->post_content;
if(strlen($the_content)) {
preg_match(”//”, $the_content, $matches);
if(!$matches) {
preg_match(”//U”, $the_content, $matches); }
$the_image_ext = substr($matches[2],-4);
if ($the_image_ext == “.JPG”) {
$the_image_ext = “.jpg”; }
$the_image_num = substr($matches[2],-11,-7);
$the_image_src = substr($matches[2],0,-4);
$the_image_150 = $the_image_src . ‘-150×150′ . $the_image_ext;
$the_image_src = substr($matches[2],0,-12);
$the_image_300 = $the_image_src . ‘-150×150′ . $the_image_ext;
$the_image_raw = $matches[2];
if ($the_image_num==”150x” || $the_image_num==”300x” || $the_image_num==”600x” ) {
$the_image = ”;
} else {
$the_image = ”;
}
return $the_image;
}
}
}
Just an update.
The thumbnail size is available in Settings -> Media Settings in Wordpress 2.9
I still confuse with this plugin installed, I try to install this plugin but my themes broken whats wrong ?
heya, thank you very much for this !!!
i am having troubles tho, somehow the EXCERPT function does not work properly any more …
look at my HOME page – the top article is an article with excerpt text, but it is not used. And the excerpts are linking to excerpts only.
i tried to change the code (sorry NO expert !!!) like this:
ID, “thumb”, true);
if ( ($thumb != “”) || is_home() || is_archive() )
{ ?>
<a href="” title=”">
<img src="” alt=”" class=”thumb” />
> ]’); ?>
> ]’); ?>
but it wont work
any ideas
ooooups !!!
[code]
ID, "thumb", true);
if ( ($thumb != "") || is_home() || is_archive() )
{ ?>
<a href="" title="">
<img src="" alt="" class="thumb" />
> ]'); ?>
> ]'); ?>
[/code]
dammit i start feeling silly now, not knowing how to post code here … grrrr..
ID, "thumb", true);if ( ($thumb != "") || is_home() || is_archive() )
{ ?>
<a href="" title="">
<img src="" alt="" class="thumb" />
> ]'); ?>
> ]'); ?>
right, i give up, i post it on the website, top article, sorry about this !!!!! :’(
heya, thank you very much for this !!!
my problem is in wordpress, getting the thumbnail which sending by wordpress script as default. simple solution that i have looking for. thx
that’s what i want!! i’ve been finding sth like this, you know, not plugin.
If the attachment is a spirit. pandora charmThen give the courage and the state is. Not or should not have to give up on the bold. pandora jewellery to wear it, will give you courage, hurried life, limited life, not allow me to attack on all fronts, spread their time and effort. In the good times in the end nothing was busy.Stubborn stubborn stubborn is arbitrary. Than face the reality on the wound and the courage to give up the powerless but the bullet that holding on the persistence, in a clear selection, see the fulcrum of their own willpandora beadsis not only more to bring you the appearance of self-confidence, more of a mental and physical encouragement, everything becomes simple and clear camel was quiet. Interference is still out heart trouble, forget the failure of depression, painful memories hidden closure. Firmly to the past, many trampled, leaving behind a clear choice pandora saleof the moment, it is to opt for the instant growth.
So beautiful story, now you do not have to links of london charms look for clover in the grass and links of London store has beautiful clover also bring you happiness. With this 18ct gold with links of london charms diamond accent four leaf clover charm. Wear this charm to put lady luck on your side or for some divine inspiration. Most of girls like to bring clover with links of London necklace, because of links of London jewelry and its bracelets, necklaces together is perfect.
Thanks for these tips; i was able to make my thumbnails appear in my main post (magazine style theme)… chmod was not working with my theme even they have instructions to do so; my hosting company was not able to figure out.
The custom field works well! I am happy. Thanks a lot!
my problem solved thanks…
Would be nice if using plugin from linkwithin.com
great post by the author, and explained very detail how to add it and I ma going to use this in my site and get rid of plugin and issues
nothing new to me, but still thanks…
Excellent post it resolved my big problem.
Another way of achieving this is given at globinch.com . Read How to Create WordPress Thumbnail Based Post Archives
http://www.globinch.com/2010/11/01/how-to-create-wordpress-thumbnail-based-post-archives/
Nice tutorials,
I have another tutorials related to this post but no custom fields, featured image required, the code automatically get the first image and set to thumbnail.
This gonna save your time editing and creating thumbnail or adding custome and featured image.
http://www.sutanaryan.com/blog/web-development/automatic-wordpress-thumbnail-without-custom-field-and-featured-image
L8KxNr http://dhY3n0fjvTtj48mG9sFnCv.com
does this still work in the latest version of wordpress?
greatful artical for me . isearch for otherthing but i’ll do it now. But i wonder, on my site’s main page, the psot seems excerpt mode and the text semms my thumb’s near. İ don’t want to this. So What i can do, to show my thumbs middle-up the post parts. You can help me for this? So sorry for my english bad so May be i cant tell correctly
StrikePill.com HALOWEEN Great live animated wallpapers, screensavers and clock collection for windows 8/7 (x64/x86)
Lonely Stick Sakura Blossom HD Live Animated Wallpaper for Android OS.
Beautiful Sakura Theme of Live Animated Wallpapers for Sakura lovers!
Really Full HD, Really 3D.
No any static pictures – truly 3D Animation in Full HD appearance.
The Lost Waterfall HD Live Animated Wallpaper for Android OS.
Beautiful Waterfall Cascade Theme of Live Animated Wallpapers for Waterfall lovers!
Really Full HD, Really 3D.
No any static pictures – truly 3D Animation in Full HD appearance.