2016-01-22 101 views
-1

我在店面的我的子主題中使用自定義大拇指。我正在使用ACF轉發器將圖像添加到滑塊。爲了顯示我很容易地使用此代碼爲woocommerce早期定製尺寸的圖像:非法字符串偏移「大小」

$slider_image = get_sub_field('slider_image'); 
$custom_image = $slider_image['sizes']['home-slider']; 

,這裏是我如何註冊功能自定義圖像:

function addthemesupport() { 
remove_theme_support('post-thumbnails'); 
add_theme_support('post-thumbnails', array('post', 'page', 'product')); 
//custom sizes: 
add_image_size('home-slider', 400, 300, true); 
add_image_size('home-featured', 200, 150, true); 
} 
add_action('after_setup_theme', 'addthemesupport', 11); 

但是我得到的前端此錯誤:

警告:非法字符串偏移'尺寸'在...

警告:非法字符串偏移「主頁滑塊」在...

這些有什麼問題?我拿了這部分代碼: custom_image = $ slider_image ['sizes'] ['home-slider']; 來自ACF文檔

+0

[參考 - 這個錯誤在PHP中意味着什麼?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – rnevius

回答

1

解決的辦法是將圖像字段設置爲對象,而不是像我在ACF中的「Url」。這樣大小的數組工作正常。