Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How should I handle post thumbnails? Do most people put them in custom fields? Use a plugin? How do themes on ThemeForest handle this?

Also different theme will have different size requirements? So moving from 1 theme to the next could cause alot of problems?

Thumbnails may come in different sizes too

share|improve this question

2 Answers 2

up vote 6 down vote accepted

Since WordPress 2.9, you can add thumbnail support to your theme by adding this to the theme's functions.php file:

if ( function_exists( 'add_theme_support' ) ) { 
  add_theme_support( 'post-thumbnails' ); 
}

When this is done, you'll be able to add a feature image to your post on Posts, Pages or Custom Post Types. You'll see the "Featured Image" box when creating a new post.

You can set the thumbnail size also in your functions.php file. You can use WordPress' "thumbnail", "medium" and "large" sizes, create your own or specify a size with pixels:

the_post_thumbnail('thumbnail');       // Thumbnail (default 150px x 150px max)
the_post_thumbnail('medium');          // Medium resolution (default 300px x 300px max)
the_post_thumbnail('large');           // Large resolution (default 640px x 640px max)

the_post_thumbnail( array(100,100) );  // Specify resolution
//Add your own:
add_image_size( 'category-thumb', 300, 9999 ); //300 pixels wide (and unlimited height)

Example of how to use this new Post Thumbnail size in theme template files.

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

You should check Codex's page on Post Thumbnails for more info. There you'll also find how to style your thumbnails and more details on this code.

share|improve this answer
    
While I'm at it, is there any recommended thumbnail sizes? The default is square, I see many themes have rectangles, is there any recommened sizes? Those of ad banners maybe? –  Jiew Meng Feb 14 '11 at 1:48
    
I guess it just depends on the rest of your theme. There's no standard than I know of other than WordPress' preset values. –  Fernando Briano Feb 14 '11 at 2:55

Thumbnail handling is basically combination of two factors - standards and meta information.

  1. Native post thumbnails are standard and have meta info.
  2. Custom fields can hold meta info about thumbnail, but there is no standard.
  3. Post content can be mined for images (no meta, no standard).
  4. Something really custom, like assigning thumbnails depending on post categories, etc.

If you have control over content form the start it is easier to choose some method and stick with it. If you don't have control or content predates post thumbnails it is more tricky. Personally I use Get The Image that is single wrapper to run multiple methods to fetch thumbnail (with your own callback if needed).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.