Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Scott

like image 995
Scott Avatar asked Oct 06 '10 16:10

Scott


People also ask

How do I make all featured images the same size in WordPress?

To change the default images sizes in WordPress:From the WordPress dashboard, select Settings > Media. In the number fields next to Thumbnail size, input the desired dimensions for your featured images. (Note: WordPress uses the terms “thumbnail” and “featured image” interchangeably.)

How do I hide featured images on individual posts in WordPress?

Select a post for which you'd like to hide the featured image. Under the Post tab (to the right) find the Featured Image section. With the plugin now installed, you'll see an option to “Display featured image in post lists only, hide on singular views.” Mark that checkbox to activate the feature.

How do I create a dynamic featured image in WordPress?

Install and Activate Plugin Before you can start selecting multiple dynamic featured images, you first have to install and activate the plugin. You can do this by going to the Plugins page of your WordPress admin dashboard. Once you are there, simply search the plugin name and it will automatically pop up.

How do I fix the featured image from auto cropping in WordPress?

Install Crop-Thumbnails plugin To install the plugin, go to Plugins → Add New and search for “Crop-Thumbnails“. Click Install Now to install the plugin, and activate it once it's installed.


2 Answers

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/

like image 53
Gavin Avatar answered Nov 15 '22 19:11

Gavin


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.

like image 31
Александр Фишер Avatar answered Nov 15 '22 19:11

Александр Фишер