高级自定义字段-Wordpress
使用自定义字段插件时,无法获取它返回任何数据。
While using the Custom Fields Plugin, I cannot get it to return any data.
我创建了一个名为 book_cover_thumbnail 链接了一篇帖子。谁能看到下面的代码为什么不起作用?
I have created a field group called book_cover_thumbnail
which has one post linked to it. Can anyone see why the code below would not work?
<img src="<?php get_field('book_cover_thumbnail');?>" />
我一点都没有错误,没有空格。
I get no errors at all, no white space.
确保您是a)使用 the_field()
或 echo回显字段get_field()
,和b)此代码位于wordpress循环中,如下所示:
Make sure you are a) Echoing the field using either the_field()
or echo get_field()
, and b) this code is either within the wordpress loop like this:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>`
<img src="<?php echo get_field('book_cover_thumbnail');?>" />
<?php end while; endif; ?>`
或者您将帖子ID添加到 get_field()
作为参数:
Or you add the post id to the get_field()
function as a parameter:
$post_id = *your_post_ID_here*;
<img src="<?php echo get_field('book_cover_thumbnail', $post_id);?>" />
文档:
使用 get_field()
: http ://www.advancedcustomfields.com/resources/functions/get_field/
使用 the_field()
: http://www.advancedcustomfields.com/resources/functions/the_field/
所有高级自定义字段文档: http:// www .advancedcustomfields.com / resources /
All Advanced Custom Fields Documentation: http://www.advancedcustomfields.com/resources/