2015-02-06 87 views
0

伊夫在我functions.php文件做了一个自定义图片大小add_image_size预先自定义字段图像 - WordPress的

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] ;?>"/> 
+0

当你看到'var_dump($ image);'? – rnevius 2015-02-06 09:55:52

+0

Theres颇多,但是这部分与blog_image在 [“blog_image”] =>字符串(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)}} – 2015-02-06 10:00:29

+0

您可以使用完整输出编辑您的问题吗?评论不会很好地格式化。 – rnevius 2015-02-06 10:03:13

回答

0

根据您var_dump()你要正确访问URL的图像。它应该是:

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

谢谢!这工作:) – 2015-02-06 10:29:30

+0

很高兴我能帮助! 'var_dump()'是发现变量内容的非常有用的工具。绝对将其添加到您的工具集! – rnevius 2015-02-06 10:30:33

+0

我知道我的老板总是告诉我用它哈!我有点新手,在我工作之前,CMS总是静态的 – 2015-02-06 10:33:11