2015-02-06 35 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

相關問題