Custom Thumbnail Sizes With WordPress 2.9+

Posted by Me (Kris Jay) & Written on Aug.13, 2010

hrbg

Since WordPress 2.9, there has been a function called the_post_thumbnail(). This is a new function that allows you to use a thumbnail attached to a post as the featured image. This is a fantastic feature that WordPress 2.9 up offers, supplying you with a picture to go along with your post (visual appeal) that helps draw people in. In order for you to use the feature the_post_thumbnail(), you need to enable it on your site (if it's not already).

The simple way of doing this is adding a quick line to your functions.php file (if you don’t have one, just create it and upload it to your theme folder).

All you have to do is add this line:

add_theme_support( 'post-thumbnails' );

This lets you to set a thumbnail in the 'Add New' Post/Page pannel's right sidebar (look at the bottom-right) in your administration.

Now you're asking me, "That's all fine and sweet Kris, but how can you have different thumb sizes with WordPress??" The answer is quite easy. Let me explain.

WordPress has a built in feature to create thumbnails....any size, any dimention. So lets say you want to have thumbnails that are 80px by 80px, you could just go into your settings menu and set it up so all your smallest thumbs are set to those dimentions. But thumbnails for different plugins, slideshows, or general use are usally all different sized, and the 150px by 150px standard is quite a nice size. So once again we bring out our trusty functions.php file, and make some additions.

By adding one simple line of code, we can create a new size of auto created thumbnails to use throughout your theme.

Just add this line right after the previous entry:

add_image_size(handle, width, height, [hard crop]);

This lets WordPress know that you want to create a new thumbnail size.I'll explain the parimeters that need to be filled.

The 'handle' is a unique identifier for that spicific thumb. This can be called whatever you wish, and will be used to call the thumb in a template tag. 'width' and 'height' ...well, if you don't know what they're for you should stop reading now. And last the parimeter [hard crop], which can be set to true for nice evenly croped images, or false for stretched images (depending on your desired use of the thumb and how it will look), but true is suggested. So lets put the parimeters together and make the new thumbs.

First off lets call the 'handle' for this example 'kjd-thumb', with a width and height of 80px; hard crop true.

We would add the code:

add_image_size('kjd-thumb', 80, 80, true);

This would produce a custom 80px by 80px, cropped image that can be called using the template tag:

<?php the_post_thumbnail('kjd-thumb'); ?>

By adding 'the_post_thumbnail();' to a custom post or page template you can utilize the existing functions WordPress offers, delivering a custom size thumbnail without relying on extra auto thumbnail creation scripts that can slow down your site and cause unwanted bandwith use.

The image right beside here is an example of a WordPress created 80px by 80px thumb using the method I have provided above. Click it, and you will notice that the image dementions that WordPress adds to all thumb image names (in the url) states 'postthumb-80x80.jpg'.

The beauty of this extra little addition to your functions.php is that it can be repeated (using a different 'handle' for each entry) over and over, creating a large selection of custom thumbnail sizes that you then can use throughout your site. This is a great thing about the functions.php file. You can make changes to the core of WordPress, without actually making changes to the core itself! Sweet!!..

hrbg

I Have Written 46 Posts So Far!

hrbg
Getting The Latest Tweet...
hrbg
Looking For Custom WordPress Web Development? Contact Graphic Dreams Studio

hrbg

the tags: , , , , , , ,

hrbg
» «
hrbg
Creative Commons License

Leave a Reply


hrbg

Grunge Style Backgrounds – Download

The second thing I'm tossing out for download tonight is a pack of 24 Grunge-Style backgrounds in a nice little .zip (well 31.5 MB's) for you to snag. Each back...

read more

Blood Splatter Screensaver – Dexter

Popping on today because I was a little bored at work, so I figured I'd make something to give away and be able to use myself. If you know me, you know that I l...

read more

Carbon Fiber Texture

Here is a carbon fiber texture that could be used for backgrounds, or chopping up to use for smaller projects. The file is 1000px by 1000px, so it gives you som...

read more


Cmin.us Social Bookmarks – WP Plugin

Cmin.us Social Bookmarks WordPress Plugin simplifys the way you and your surfers get ShortURLs and Submit Your Posts to Social Media/Bookmarking Sites.The Plugin places a...

read more

Author Tweets – WordPress Plugin

This is a WordPress Plugin for multi-author, and personal websites/blogs. It displays the 'About the Author' box at the end of all posts, with a Twitter Twist. I have com...

read more

WordPress Tetris – WordPress Plugin

This Plugin is just for fun, and can take up a bunch of your time once you start playing. Everyone knows/has played the game Tetris, well I decided it was time that WordP...

read more




"Ignorance is the foundation of atheism, and freethinking the cure of it"
Anthony Collins - 1676-1729