【问题标题】:Advanced Custom Fields Sub_Field in Archive Page存档页面中的高级自定义字段 Sub_Field
【发布时间】:2016-01-15 04:27:25
【问题描述】:

我在 Wordpress 中使用带有中继器插件的 ACF 插件,通常在 archive.php 中我可以使用 get_fieldthe_field 函数,这些函数显示帖子的数据。 (例如:标题)

在single.php中没有问题,当我想在archive.php中使用the_sub_fieldget_sub_field时,

Image of Repeater Field Name

archive.php 中,下面的示例显示我没有单词。我怎样才能看到“是”字?我该怎么办?谢谢。

<?php
    if( have_rows('add_content') ):
        echo "Yes";
    else :
        echo "No";
    endif;
?>  

【问题讨论】:

  • 没有中继器...(如果没有 add_content 它会拒绝)。
  • 帖子有 add_content 数据,但在存档页面中,我无法获取。

标签: wordpress repeater advanced-custom-fields


【解决方案1】:

您需要一个 if/while 语句才能使中继器工作。

 <?php if (have_rows('add_content')){ ?>
     <?php while (have_rows('add_content')) { the_row(); ?>
        Yes
     <?php } // while:   ?>
 <?php } else { ?>
       No
 <?php }  ?>

【讨论】:

  • 谢谢Aibrean,但它在single.php 中工作,在archive.php 中不起作用,我的意思是在类别页面中,它不会从任何帖子中获取转发器数据。例如,我有一个帖子,它有转发器字段。在分类页面中,我无法获取该帖子的转发器字段的数据。
  • 您是否将其放入该帖子的循环中?
猜你喜欢
  • 2012-09-27
  • 2021-03-22
  • 2015-05-27
  • 2016-06-28
  • 2021-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多