2012-09-08 57 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. ?> 
相关问题