高级自定义字段-Wordpress [英] Advanced Custom Fields - Wordpress

查看:104
本文介绍了高级自定义字段-Wordpress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用自定义字段插件时,无法获取它返回任何数据。

While using the Custom Fields Plugin, I cannot get it to return any data.

我创建了一个名为<$的字段组c $ c> 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/

这篇关于高级自定义字段-Wordpress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆