$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>categories - How to change the thumbnail size to a specific category?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin9PV0评论

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
Post a comment

comment list (0)

  1. No comments so far