add_image_size提前自定义字段图像 - wordpress

时间:2015-02-06 09:51:18

标签: php wordpress function advanced-custom-fields image-size

我在我的functions.php文件

中制作了自定义图像大小
add_image_size('blog_image', 417,300, true);

然后我的代码在php文件中显示我的图像

<?php $image=get_field("post_image");?>
style="background:url('<?php echo $image['url']['blog_image'];?>');"

如果我拿出['blog_image']我的图片出现在页面上(没有缩放图片),但是当它添加时没有图像

当我做var_dump时,我得到了

array(10) {
    ["id"]=> int(672) 
    ["alt"]=> string(0) "" 
    ["title"]=> string(16) "google-maps-logo" 
    ["caption"]=> string(0) "" 
    ["description"]=> string(0) "" 
    ["mime_type"]=> string(10) "image/jpeg" 
    ["url"]=> string(70) "http://192.168.242.108/wp-content/uploads/2014/12/google-maps-logo.jpg" 
    ["width"]=> int(1024) 
    ["height"]=> int(1024) 

    ["sizes"]=> array(18) {

        ["thumbnail"]=> string(78) "http://192.168.242.108/wp-content/uploads/2014/12/google-maps-logo-150x150.jpg" 
        ["thumbnail-width"]=> int(150) 
        ["thumbnail-height"]=> int(150) 
        ["medium"]=> string(78) "http://192.168.242.108/wp-content/uploads/2014/12/google-maps-logo-300x300.jpg" 
        ["medium-width"]=> int(300) 
        ["medium-height"]=> int(300) 
        ["large"]=> string(70) "http://192.168.242.108/wp-content/uploads/2014/12/google-maps-logo.jpg" 
        ["large-width"]=> int(1024) 
        ["large-height"]=> int(1024) 
        ["home_box_image"]=> string(78) "http://192.168.242.108/wp-content/uploads/2014/12/google-maps-logo-480x320.jpg" 
        ["home_box_image-width"]=> int(480) 
        ["home_box_image-height"]=> int(320) 
        ["team_member"]=> string(78) "http://192.168.242.108/wp-content/uploads/2014/12/google-maps-logo-394x371.jpg" 
        ["team_member-width"]=> int(394) 
        ["team_member-height"]=> int(371) 
        ["blog_image"]=> string(79) "http://192.168.242.108/wp-content/uploads/2014/12/google-maps-logo-417x1000.jpg" 
        ["blog_image-width"]=> int(417) 
        ["blog_image-height"]=> int(1000) 
    } 
}

另一个add_image_size(team_member)适用于我使用要素图像的另一个页面,但我无法使用此部分的要素图像。这是有效的图像

<img src="<?php echo wp_get_attachment_image_src($attachmentID, 'team_member')[0] ;?>"/>

1 个答案:

答案 0 :(得分:0)

根据您的var_dump(),您尝试错误地访问该网址。它应该是:

$image['sizes']['blog_image'];