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!!..
the tags: custom, functions, images, php, sizes, thumbnails, thumbs, wordpress









