未设置特色图片分辨率 [英] Featured Image Resolution not set

查看:46
本文介绍了未设置特色图片分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为不同分辨率的特色图片添加代码.像缩略图,中等,大和完整.但我想看起来像这种分辨率.例如125x125150x150.250x250我正在尝试此代码.但它不起作用.<代码><a href="<?php echo $thumb_url[0];?>"download="image-300x300" target="_blank">300x300</a></br>

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>

显示全尺寸图像.

推荐答案

您需要在 functions.php 文件中添加不同的图像大小.WordPress 将在创建新图像时创建这些调整大小的图像.

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.

用法如下:

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

有关 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:

functions.php里面:

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

在您的主题中:

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

这篇关于未设置特色图片分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆