简体   繁体   English

类别页面上的 ACF 组

[英]ACF group on category page

I have created fields group for my blog categories using Advanced Custom Fields ( https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/ ).我使用高级自定义字段 ( https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/ ) 为我的博客类别创建了字段组。

When i create basic text field, it is easy to echo it on category.php using:当我创建基本文本字段时,很容易在 category.php 上使用:

$terms = get_the_terms( get_the_ID(), 'category');

if( !empty($terms) ) {
    $term = array_pop($terms);
    $custom_field = get_field('some_text_field', $term );
}

echo $custom_field;

But instead of basic text field i created a group (called call_to_action) with 4 fields inside it (image, title, subtitle, link).但是我创建了一个组(称为 call_to_action)而不是基本的文本字段,其中包含 4 个字段(图像、标题、副标题、链接)。 Now, if i try to create different variables, like:现在,如果我尝试创建不同的变量,例如:

$custom_field1 = get_field('image', $term );
$custom_field2 = get_field('title', $title );
$custom_field3 = get_field('subtitle', $title );
...

and echo them, nothing happens.并回应他们,什么也没有发生。

I am guessing this is because they are located in "call_to_action" group... and i really dont know how to make them show up... I am only starting with PHP and any ideas would be really greatly appreciated我猜这是因为它们位于“call_to_action”组中......我真的不知道如何让它们出现......我只是从 PHP 开始,任何想法都会非常感谢

Try This way试试这个方法

$custom_field3 = get_field('subtitle');

OR或者

global $post;  
$custom_field3 = get_field('subtitle',$post->ID);

OR或者

$custom_field3 = get_field('subtitle',get_the_id());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM