如何从字段中调用WordPress中的自定义缩略图图像大小?

时间:2017-09-29 15:57:32

标签: wordpress

我在我的主题中添加了一个功能,允许用户“上传”图库的图像。该字段称为“缩略图”,它返回一个网址(“http://example.com/wp-content/upload/image.jpg”)。

我的问题是我添加了新的缩略图尺寸(add_image_size()),重新生成照片,但现在我在调用新图像时出现问题。

示例:

我尝试过使用preg_replace但它不允许使用各种文件名,大小和文件扩展名。如何调用该URL,并添加新的图像大小?

1 个答案:

答案 0 :(得分:0)

您需要的代码在图像的ACF文档中提供:

<?php 
$image = get_field( 'image' );
$size = 'full'; // (thumbnail, medium, large, full or custom size)

if( $image ) {
    echo wp_get_attachment_image( $image, $size );

}
?>

请参阅:https://www.advancedcustomfields.com/resources/image