categories - How to change the thumbnail size to a specific category?

admin2025-06-02  4

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?

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?

Share Improve this question asked Jan 27, 2014 at 13:57 Riffaz StarrRiffaz Starr 7964 gold badges20 silver badges41 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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:

  • Conditional tags
  • in_category
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748869678a314399.html

最新回复(0)