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.

Is there any way to auto-generate a 150x150 thumbnail image for each post based on the post's selected featured image? This would be preferable as opposed to manually going into each post, copying the images 150x150 image URL and pasting it thumb custom field.

share|improve this question
add comment

1 Answer

Inside your post loop you can do;

 if ( has_post_thumbnail()) {
 echo get_the_post_thumbnail($post->ID, 'thumbnail');
 }

This first checks for the existence of a featured image and if so it will display one at your default 'thumbnail' size as set in your settings/media options.

This would also work within your loop;

 if ( has_post_thumbnail()) {
 the_post_thumbnail('thumbnail');
 }

This would work (but can be used outside of your loop);

 $id = get_the_ID();
 echo get_the_post_thumbnail($id, 'thumbnail');

Beyond that there are other functions to help you customize sizes should that not achieve what you want. However the above defaults to 150x150.

Let me know how you go.

share|improve this answer
    
So this will create a new record in the postmeta table? –  keruilin May 19 '12 at 15:44
    
@keruilin No. The thumbnails have already been generated for you when you upload an image, Full Size (original image size) then several other sizes are generated automatically by WP. Using the above you are simply telling WP to show a thumbnail "here" with "here" being wherever you insert the call into your theme file and the thumbnail declaration which specifies which size of the image you want returned. –  userabuser May 19 '12 at 16:43
add comment

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.