【发布时间】:2012-09-02 05:26:10
【问题描述】:
我正在使用 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
【问题讨论】:
-
只是看着它,并不太了解 Wordpress,您使用
the_field('thumbnail')调用它的方式是以字符串形式返回一个逗号分隔的列表,带有缩略图 可能 在索引 #5 处(零是第一个)。所以要么你向函数传递了错误的值,要么你应该以某种方式解析它($thumb = explode(', ', the_field('thumbnail'));,然后使用$thumb[5]),或者类似的东西。 -
the_field('thumbnail') 是高级自定义字段插件功能的字段调用方式
-
调用
the_field('custom_title');是否返回正确的值,即“我的自定义标题”? -
是的,“the_field('custom_title');”返回我在帖子自定义字段框中写的自定义标题。
-
你真的需要看看你得到了什么,并试着弄清楚你为什么得到它。您还应该有来源,因此参考它并找出您获得特定结果的原因也应该是富有成效的。您can get the url from the returned function call,但这似乎需要做很多工作,所以请先检查您是否做对了。