From your comment:
This is all I meant: add_image_size( 'index-thumb', 640, 250, true ); add_image_size( 'image-format', 630, 9999, true );
So, let's assume you create custom image sizes for gallery
and video
(as well as a "default" size, which we'll call standard
), perhaps like so:
<?php
add_image_size( 'index-standard', 640, 250, true );
add_image_size( 'image-gallery', 630, 9999, true );
add_image_size( 'image-video', 700, 9999, true );
?>
Now, in your template, where you want to output the custom image size, let's figure out which one to use, via get_post_format()
, like so:
<?php
// Determine post format
$post_format = ( get_post_format() ? get_post_format() : 'standard' );
// Set image size based on post format
$thumbnail_size = 'image-' . $post_format;
// Output post thumbnail
the_post_thumbnail( $thumbnail_size );
?>
That should be it.
Note: By using get_post_format()
, all you have to do is register the image size for each supported format, and you're done. You can use has_post_format()
, but you'd have to add explicit code for each supported format, like so:
<?php
$thumbnail_size = 'image-standard';
if ( has_post_format( 'gallery' ) ) {
$thumbnail_size = 'image-gallery';
} else if ( has_post_format( 'video' ) ) {
$thumbnail_size = 'image-video';
}
the_post_thumbnail( $thumbnail_size );
?>
You could also use a switch
instead of an if/else
; either way, it's more efficient to use the get_post_format()
method, above.