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.
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.
- Read: get_the_post_thumbnail
- Read: the_post_thumbnail
Let me know how you go.
-
-
@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.– AdamCommented May 19, 2012 at 16:43