2012-09-08 59 views
3

我工作在WordPress網站上,我想從一個崗位的高級定製領域的縮略圖,這樣的:高級自定義字段縮略圖 - WordPress的

<?php while (have_posts()) : the_post(); ?> 
    <h1><?php the_field('custom_title'); ?></h1> 
    <img src="<?php the_field('thumbnail'); ?>" alt="" /> 
    <p><?php the_content(); ?></p> 
<?php endwhile; // end of the loop. ?> 

那就是當問題我加載網頁,圖像變得看起來像這樣的網址:

<img src="5, , item_alt2, , , http://portfolio.local/wp-content/uploads/2012/09/item_alt2.jpg, Array"> 

所以,據我看到的,因爲容貌的圖像它的工作的插件,但它會加載一個奇怪的路徑,因此它顯示像「破碎」的圖像。

我做錯了什麼?

5, , item_alt2, , , http://portfolio.local/wp-content/uploads/2012/09/item_alt2.jpg, ArrayNULL 
+0

,只要看一眼,不知道WordPress的那麼好,你用'the_field調用的方式(「縮略圖')'以字符串形式返回一個逗號分隔的列表,縮略圖*可能*在索引#5處(零是第一個)。因此,要麼將錯誤的值傳遞給函數,要麼以某種方式解析(''thumb = explode(',',the_field('thumbnail'));',然後使用'$ thumb [5 ]')或類似的東西。 –

+0

the_field('thumbnail')這是調用高級自定義字段插件功能的方法 – codek

+0

是否調用'the_field('custom_title');'返回適當的值,即「我的自定義標題」? – tftd

回答

7

查看高級自定義字段上的文檔;

http://www.advancedcustomfields.com/docs/field-types/image/

您作爲一個對象按照在底部的示例返回自定義字段的值;

Array 
(
[id] => 540 
[alt] => A Movie 
[title] => Movie Poster: UP 
[caption] => sweet image 
[description] => a man and a baloon 
[url] => http://localhost:8888/acf/wp-content/uploads/2012/05/up.jpg 
[sizes] => Array 
    (
     [thumbnail] => http://localhost:8888/acf/wp-content/uploads/2012/05/up-150x150.jpg 
     [medium] => http://localhost:8888/acf/wp-content/uploads/2012/05/up-300x119.jpg 
     [large] => http://localhost:8888/acf/wp-content/uploads/2012/05/up.jpg 
     [post-thumbnail] => http://localhost:8888/acf/wp-content/uploads/2012/05/up.jpg 
     [large-feature] => http://localhost:8888/acf/wp-content/uploads/2012/05/up.jpg 
     [small-feature] => http://localhost:8888/acf/wp-content/uploads/2012/05/up-500x199.jpg 
    ) 

) 
+0

總體感覺(在文檔中沒有看到),肯定會使打印的價值感增強。 –

+0

@JaredFarrish--我知道,這並不能幫助文字幾乎全部變灰!看起來像是在後來的版本添加ACF 3.3.7+ – McNab

+0

是的,它的工作哈哈,非常感謝你!只需改變返回的URL不是對象! – codek

0

你有沒有設置的CustomField返回網址。看起來它是設置爲對象。您有3個選項可以返回圖像。

+2

歡迎來到stackoverflow!請注意,這應該是一個評論,而不是一個答案。順便說一句,返回圖像的3個選項是什麼? –

+1

@Chris在添加評論之前,您需要很多聲望... –

0

或者,你可以設置自定義字段的圖片ID,並使用它像

$image = wp_get_attachment_image_src(get_field('thumbnail'), 'sizename'); 
    <h1><?php the_field('custom_title'); ?></h1> 
    <img src="' .$image[0]. '" alt=""> 
    <p><?php the_content(); ?></p> 
<?php endwhile; // end of the loop. ?> 
相關問題