0

I am using thumbnail on my blog posts. I added the following code in my functions.php for that purpose

add_theme_support('post-thumbnails');  
set_post_thumbnail_size( 328, 228, true ); 

It's working fine and all thumbnails are 328 x 228

Now I want to change the thumbnail size only for a specific category ID is 9.

Post under category ID 9's thumbnails must be 100 x 150.

how can I do that?

2

How about just use conditionals:

if ( in_category( '9' )) {
    // different size for one category
    set_post_thumbnail_size( 100, 150, true ); 
} elseif ( in_category( array( '5', '7' ) )) {
    // different size for multiple categories
    set_post_thumbnail_size( 150, 200, true ); 
} else {
    // default size
    set_post_thumbnail_size( 328, 228, true ); 
}

Reference:

  • thanks for that. I've added add_theme_support('post-thumbnails'); // enabling thimbnail on post summary - riffaz if ( in_category( '11' )) { set_post_thumbnail_size( 135, 10, true ); // different size for one category } else { set_post_thumbnail_size( 328, 228, true ); // default size } on my functions.php it's cropping the image width as 135 and 328 bout not the height. height is fixed as 197. how can I force to crop? – Riffaz Starr Jan 28 '14 at 10:10
  • 1
    You might want to read this: add_image_size – Borek Jan 28 '14 at 13:29
  • Are you sure that this code would automatically resize images on upload for all three image sizes? I don't think so. Because when the server parses the PHP, it will only collect the true condition size into the global $_wp_additional_image_sizes array. Meaning, when uploading a new image, it will only resize it to size in else condition (because there is no global $post at the moment, so in_category() will always return false). I have not tested this, though. – dboris Feb 25 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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