How To Add WordPress Post Thumbnails To Thesis

Thesis is an absolutely fantastic framework for WordPress. One of the things that is sorely lacking to date is integration of WordPress post thumbnails.

Post thumbnails have been available for use for quite some time now, and they provide a simple way of placing post images, teaser thumbnails, featured post images, thumbnail for lists of posts in your blog’s sidebar, and any other use of post images you can think of. Its not quite as efficient as the current Thesis system, but it works quite well, and the small sacrifice in terms of efficiency is well worth it for the time you’ll save if you ask me.

Setting Up Post Thumbnails

Thumbnails aren’t enabled by default, so you need to enable them manually. What you’ll need to do is place this code in custom_functions.php:

add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 610, 9999, true );
add_image_size( 'teaser', 150, 150, true );

There are three things involved here:

  1. Post thumbnails are activated using add_theme_support( 'post-thumbnails' );
  2. The default size is established using set_post_thumbnail_size( 610, 9999, true );
  3. An additional thumbnail size is established using add_image_size( 'teaser', 150, 150, true );

To add additional sizes, you’ll need to add add_image_size( 'image_name', [image width in pixels], [image height in pixels], true ); to the end of that snippet.

In order to call the thumbnails for use within your theme you’ll need to use . That will call the default size. To call a size other than the default, you need to insert the name of the image used in establishing that particular size of thumbnail within the parenthesis. For the teaser image established above, it would look like .

Using The Post Thumbnails

You can use these post thumbnails in any loop on your blog for just about any purpose you can think of. For the purposes of this post, I’m just going to show you how to set up post images and teaser images like you would normally see in a Thesis installation.

Setting Up Post Images

Thesis allows you to place post images above or below the post headline, and floated to the left or right. I’m not going to show you how to create post options to allow for that kind of differential (though its certainly possible). For this post, I’m going to show you how to hard code the post image in any of those locations.

First, you need to call the post image in a function. The image should be linked to the single post if it is appearing in a list of posts. If it is appearing on the single post, it should not be linked. That code looks like this:

function post_image() {
	if(has_post_thumbnail()) {
		if(is_single()) { ?>
			<div class="post_image">
				<? the_post_thumbnail(); ?>
			</div>
		<? }
		else { ?>
			<div class="post_image">
				<a href="<? the_permalink(); ?>" title="<? the_title(); ?>"><? the_post_thumbnail(); ?></a>
			</div>
		<? }
	}
}

We’ve also added a conditional (if( has_post_thumbnail() )) to make sure the post image is set. If its not, then this code won’t be applied.

Second, you need to use a Thesis hook to apply the post image below or above the headline. To place it above, use add_action( 'thesis_hook_before_headline', 'post_image' );.

To place it below, use add_action( 'thesis_hook_before_post', 'post_image' );.

Next, we need to write some CSS so that the post image fits with your design and the location in which you’ve placed it. You’ll probably need to add to this depending on your particular design, but here’s a starting point.

.post_image { margin-bottom: 1em; margin-left: 1em; float: right; }

Of course, if you don’t want to float your image to the right, you’ll want to remove margin-left: 1em; float: right;. If you want to float left, you’ll need to use margin-right: 1em; float: left; in its place.

You may also want to make use of the margin, padding, background, and border properties. That, however, is largely dependent upon your design.

Setting Up Teaser Images

Like post images, you need to start with a function to setup the post image. The one main difference is that teaser images will always be linked to the single post because they will never show up on the actual single post. That function looks like this:

function teaser_image() {
	if(has_post_thumbnail()) { ?>
		<div class="post_image">
			<a href="<? the_permalink(); ?>" title="<? the_title(); ?>"><? the_post_thumbnail(); ?></a>
		</div>
	<? }
}

Again, we’re using a conditional to dictate that if their is no post thumbnail set, then the code is not applied. In order to add this to our teaser, we need to use add_action( 'thesis_hook_before_teaser_headline', 'teaser_image' ); or add_action( 'thesis_hook_after_teaser_headline', 'teaser_image' );. Those should be fairly self explanatory ;)

Once again, you’ll need to add CSS to make this fit with your design. A good starting point is the exact same as the post images. Again, the CSS looks like:

.post_image { margin-bottom: 1em; margin-left: 1em; float: right; }

Again, depending on the specifics of your design, you’ll probably want to make use of margin, padding, background, and border in your CSS code.

Other Uses

You can use WP post thumbnails for featured posts, related posts in your post footer, popular or favorite posts in your sidebar, and the list goes on. If you’ve got any questions, please let me know in the comments!

Liked this post? Get free updates via RSS when we post or

Written by

I'm a freelance web designer from a small town in Indiana. I love the Chicago Cubs, my wife, Coca Cola and dark chocolate...in that approximate order.

Bio Twitter Portfolio Contact

{ 36 comments… read them below or add one }

1 Avi D

Great post Adam!

Just not so sure why using this would be easier than using the Thesis post thumbnails in general…except the popular posts/related posts etc in the sidebar etc. :-D

That said, it’s always nice to have an option…

Reply

2 Adam Baird

Avi,

There are a couple reasons why I use them:

1. You only have to upload one image. You’re right that its especially convenient for sites using 3 or more image sizes, but the auto-resize/auto-crop is much cleaner than the script Thesis uses.

2. Forward compatibility. I typically upload images that are larger than needed. That way, if I change my design and need to change the size of the images in the future, its extremely easy to do…you just change/add the sizes in the code, and use this plugin to regenerate thumbnails according to the new sizes.

The one bad thing is that WP post thumbnails are assigned IDs in the database. Thesis images are not (unless you upload them using the media uploader)

Reply

3 Avi D

I just learnt that Thesis thumbnails don’t work for excerpts. Would this script work for excerpts?

Reply

4 Adam Baird

Teasers are excerpts, so yes. For the record, Thesis does offer an opportunity to designate the URL of a post thumbnail in addition to a post image. Those post thumbnails do show up with excerpts.

Reply

5 rohan

I think thesis treats teasers and excerpts differently.
While Teaser length and thumbnail can be assigned and fetched from the “page break” option in WP post edit, excerpts are explicitly defined while making the post.If you use excerpt and dont define the image as featured then it will not show images like @Avi D says.
While excerpts can be fetched automatically ,teasers have to be defined every time a new post is made.

Reply

6 Adam Baird

Rohan,

Whether you’re using Thesis thumbnails or wp post thumbnails, they will show up with excerpts – manual or automatically generated. That is, of course, assuming you’ve hooked the images in the correct place.

Reply

7 rohan

Thanks,

The reply provided a hint to the error in my blog “hooked properly” :)
I had uploaded my code file first then edited the hooks offline and forgot to upload it. thanks to ur reply it reminded me to upload it and its working fine now.

Reply

8 flat shoes

I just simply use on custom .post_image {width: xx px; height: xx px} . I think same purpose i.e avoid upload double images for thumbnails on thesis themes

Reply

9 Adam Baird

You’re right that you can use the same image and re-size it. However, there are two main problems with this option:

1. The image is usually distorted and not proportional.

2. You’re adding weight to your page load. Let’s say the average post image you upload is 50KB. Let’s say the average thumbnail would be 10KB. That’s 40KB per thumbnail that you’re displaying using your CSS re-sizing method. If you’ve got 5 thumbnails in your sidebar, that’s 200KB of extra page load for no reason. If you’re one of those sites that displays 10, 15, 20 or more, you could be adding a full MB to your page load. That seems a bit silly to me.

Reply

10 Dawn

Hi Adam – great blog and articles! Thanks for all of the great suggestions.

One request that I have is to add dates to your articles so we know how recent they are, particularly since you refer to “the latest version” of Thesis.

I’m really impressed with the design and layout of your blog.

Reply

11 Dawn

To clarify, is this post still valid with Thesis 1.8?

I’m a newbie to Thesis and noticed that version 1.8 has a Post Images and Thumbnail section. I’m not sure if that makes this post obsolete.

Reply

12 Adam Baird

Dawn,

Thesis does have its own built in post image and thumbnail system, but it pre-dates the WP system, and lacks a bit of the flexibility, and polish that the WP system offers. The Thesis system will get the job done for most setups, but if you want three image sizes or more, you’ll have to do something similar to what is discussed in this post.

Hope that clarifies!

Reply

13 Dawn

Thanks, Adam! It’s still a little confusing to me but I like the idea of having the flexibility of multiple size images from one upload and will experiment with this technique. (I’m going to try PHPThumb to resize images.)

Does your script override settings in Thesis for thumbnail management? For example, I currently have # Show images on single entry pages and # Show images on archives pages checked in the Default Post Image Settings.

Thanks again!

Reply

14 Adam Baird

Dawn,

Thesis post images only appear for posts where you’ve inserted image URLs into the appropriate fields for post image and thumbnail in the post option meta boxes when creating the post.

As for using this technique, you don’t need to use any script!!! The code in this post accesses the WordPress script that manages post images. It all works automatically. All you’ll need to do is choose a “featured image” when you create a post. That’s it.

Reply

15 Dawn

Thanks again!

I’m glad that I don’t need any other script because apparently PHPThumbs is not working. I installed Regenerate Thumbs and am completely lost on how that works but will deal with that another time.

As for your script working automatically, how does it know which size thumbnail to generate? (Sorry for the newbieness.)

Reply

16 Adam Baird

add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 610, 9999, true );
add_image_size( 'teaser', 150, 150, true );

That snippet of code establishes post thumbnail support for Thesis, sets default size, and adds an additional image size.

set_post_thumbnail_size( 610, 9999, true ); establishes the default size as 610px wide, up to 9999px high. add_image_size( 'teaser', 150, 150, true ); creates an additional image size of 150px wide and 150px high. If you wanted to set up a third size, it would look like this: add_image_size( '[image name]', [width in pixels], [height in pixels], true );

Reply

17 Dawn

I’m confused by this statement on how to “call the image”:

In order to call the thumbnails for use within your theme you

Reply

18 Dawn

Oops, please ignore my latest post … I was trying to clarify my question and your answer crossed with my question.

Thank you very much!!!!!!

Reply

19 Adam Baird

No worries! Hope you got it figured out!

Reply

20 Dawn

I’m pretty adept at dealing with PHP … have successfully installed and edited many PHP scripts.

However, I’m confused with css_functions. I copied-and pasted your code exactly but got a white screen error. Should I be entering <?php and <php? in the opening and closing code?

Reply

21 Adam Baird

You shouldn’t need to. Also, I’m assuming you’re referring to custom_functions.php?

Obviously the code needs to be inserted after the opening “<?php"

Reply

22 Dawn

Yes, I meant custom_functions.php. Sorry.

Here is what I put in that isn’t working. I think the problem is that I’m putting the add_action( ‘thesis_hook_after_teaser_headline’, ‘teaser_image’ ); code in the wrong place:

add_theme_support( ‘post-thumbnails’ );
set_post_thumbnail_size( 610, 9999, true );
add_image_size( ‘teaser’, 150, 150, true );

function post_image() {
if(has_post_thumbnail()) {
if(is_single()) { ?>

<a href="” title=”">

<? }
}
}
add_action( 'thesis_hook_before_post', 'post_image' );

function teaser_image() {
if(has_post_thumbnail()) {

<a href="” title=”">

<? }
}
}
thesis_hook_after_teaser_headline', 'teaser_image' );

Reply

23 Adam Baird

That code appears waaaay out of whack. You’ve deleted a bunch of vital code (or it didn’t show up in the comment).

If you copy and paste the code in this post should work.

Reply

24 Dawn

Yep, it isn’t showing up correctly in the comment. :(

Reply

25 Adam Baird
26 Dawn

Here’s the FULL code for custom_functions.php for posts and teasers using Escape:

add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 610, 9999, true );
add_image_size( 'teaser', 150, 150, true );

function post_image() {
if(has_post_thumbnail()) {
if(is_single()) { ?>
<div class="post_image">
<? the_post_thumbnail(); ?>
</div>
<? }
else { ?>
<div class="post_image">
<a href="<? the_permalink(); ?>" title="<? the_title(); ?>"><? the_post_thumbnail(); ?></a>
</div>
<? }
}
}
add_action( 'thesis_hook_before_headline', 'post_image' );

function teaser_image() {
if(has_post_thumbnail()) {
<div class="post_image">
<a href="<? the_permalink(); ?>" title="<? the_title(); ?>"><? the_post_thumbnail(); ?></a>
</div>
<? }
}
}
add_action( 'thesis_hook_before_teaser_headline', 'teaser_image' );

Reply

27 Ian

Hi Adam,

I’ve nearly got this to work although I think there is an error in your ‘teaser’ php which is giving me problems.

First off, I created; add_image_size( ‘posts’, 200, 135, true ); to style/size my single page post images but I also had to add the following to get it to work;

(notice the addition of ‘posts’). This has got it to work although I’m not sure if this is right?

Now, I can’t get the teaser image working, in fact I get a fatal error. Checking through your code I think you have one too many ‘}’ , although removing one still gives fatal error. The other thing I find confusing is how/where do I call up the ‘teaser’ image size. Should there not be a somewhere?

Reply

28 serge

Hi , exellent snippets over here. Just wanted to share this plugin as well http://creersitepro.com/thumbnail-catcher-pro-for-thesis-theme-wordpress/ that helps to catch images either from post thumbnails or post content to generate thumbs in teasers.

Easy for those who struggle with php/css

cheers,
serge

Reply

29 Raj @ Web Hosting Coupons

I have got a strange problem, while setting up thumbnails I am getting double thumbnails in the homepage… what should I do??

Reply

30 gofur

please tell me how to add widget on single post only??

Reply

31 Military Velcro USA

Here is what I put in that isn

Reply

32 Military Velcro USA

I have got a strange problem, while setting up thumbnails I am getting double thumbnails in the homepage

Reply

33 Kulwant Nagi

Thanx for post this self explaining Article.

Reply

34 Delwar

Sure, thanks for the code. But where you want to put the second code? I mean the post image that is connecting to the single post?

Reply

35 Sanfranc

I slowly hope fact that propecia without prescription this a few little experiment present-day has shown those of you each of which slowly think fact that a little government welfare spending isn’t the jam intensively have had your eyes opened as manner late as a bit bit.But a fiery speech does impatient bring a bit bit true to piss off indifference used true to chewing beside the propecia without prescription on.At propecia without prescription a guess propecia without prescription a particular instrument in their inventory and they do without absolutely wrong intensively respond superb to your pretty email within propecia without prescription a quick-witted timeframe – all alone absolute busy d.How do without you excitedly keep your spirits up- how can you hold down positive- i’m beginning propecia without prescription to quietly think i might absolutely wrong piss off bang-up – i’m trying 3 years! my high fertility doc appointment is amazing subsequent week-any suggestions-anything i and trying propecia without prescription to conceive- ive almost only been trying in behalf of 3/4 months and its making me depressed-! it as unusually late as silent seem such that by far easier in behalf of everyone else! i gently hate about now i instantly feel such that consciously jealous of population, and piss off unhealthy if i intensively find check out someone is bang-up.Its put around strong will be at buy propecia discount a guess 1 pretty to 1., they’ll systematically need non prescription propecia a car true loan, sometimes home true loan, plastic, and perhaps non prescription propecia a graduate non prescription propecia school true loan.It is worth $6 per month at almost a high rate of your well local b.And teammates buy propecia prescription that he loves very deeply,” team president ed stefanski said.
Buy Propecia prescription
At the point where they cross country in the a few middle of the buy propecia discount is the almost approximate ic of the clock.

Reply

36 Mytechshout

Nice thesis tutorial.I have added it to my thesis blog.

Reply

Please leave your thoughts below!