Featured Image Resolution not set

妖精的绣舞 提交于 2019-12-23 04:48:34

问题


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 );


来源:https://stackoverflow.com/questions/25784959/featured-image-resolution-not-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!