Wordpress different featured image size for different post types
You can enable featured images for posts and set their size by using the following code in your function.php file:
add_theme_support('post-thumbnails');
set_post_thumbnail_size(107, 69, true);
but this sets the image size globally for any post types. Im using wordpress 3.0 and have created my own custom post type. Is it possible to apply a different featured thumbnail sizes for different post types?
Thanks
Scot开发者_开发知识库t
In your theme functions file, you can define new image sizes that apply to any images uploaded from then forward:
add_image_size('new-thumbnail-size',600,340, true)
Once you've defined a new image size, you can use the_post_thumbnail as usual but include the new image size to display that instead of the thumbnail default:
the_post_thumbnail( 'new-thumbnail-size' )
A little bit more detail: http://gavinsmith.me/2010/10/multiple-post-thumbnail-featured-image-sizes-in-wordpress/
To answer your question, currently (Version 3.4.1) it is not possible. And the reason is simple: If you upload a file to your media library your image is not related to any post nor even a post_type, so wordpress cannot know, that this file has to be resized into a different format.
Realizing your wish (as it is one of mine too) means, that the image has to be created, if an image is added to a post with a custom post type.
So until this might be realized (I do not expect that this will come in time) you have to define your custom image size globally dealing the disadvantage, that every file you are uploading will be stored multiple times (one per add_image_size()
call), even if you will use only one image in your template.
精彩评论