php - How to set the post_thumbnail size to specific category or tag?
I'm trying to create an post gallery grid with different thumbnail sizes. I want to show a different thumbnail size for posts per category. I've added thumbnail sizes in functions.php and tried to conditionally populate the post-thumbnail with custom sizes with the following code:
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
add_image_size( 'thumbvert', 500, 750, true );
add_image_size( 'smallvert', 675, 1013, true );}
if ( in_category( 'thumbvert' )) {
set_post_thumbnail('thumbvert');
} elseif ( in_category( 'smallvert' )) {
set_post_thumbnail('smallvert');
} else {
set_post_thumbnail_size( 500, 333 ); }
The thumbnails don't change.
Answer
Solution:
Going purely on what you have supplied. You'll need to get the current category name if on an archive page, then run your conditional. Ex: