Featured Image Resolution not set

2019-06-14 12:24发布

问题:

I am trying to add code for featured image on different resolution. like thumbnail, medium, large and full. But I wanna look like this type of resolution. e.g 125x125 150x150. 250x250 I am trying this code. but it's not work. <?php $thumb_id = get_post_thumbnail_id(); $thumb_url = wp_get_attachment_image_src($thumb_id,array(300,300), true);?> <a href="<?php echo $thumb_url[0];?>" download="image-300x300" target="_blank">300x300</a> </br>

It's show full size of image.

回答1:

You need to add different image sizes in your functions.php file. WordPress will then create these resized images when a new image is created.

Usage is as such:

<?php add_image_size( $name, $width, $height, $crop ); ?>

Lots more information available on the WordPress Codex.

If you wish to create these image sizes retrospectively (to images you've already added) then you'll need to regenerate your thumbnails. You can do this using the regenerate thumbnails plugin.

You can then reference a image size in your code. A full example:

Inside functions.php:

add_image_size( 'example_size', 200, 200, true );

Inside your theme:

$thumb_url = wp_get_attachment_image_src( $thumb_id, 'example_size', true );