ACF目录的灵活内容布局组

hsgswve4  于 2022-10-02  发布在  PHP
关注(0)|答案(0)|浏览(67)

我有一个ACF灵活的内容字段,布局名称为‘POST_SECTION’,它有一个名为‘Parage’的组字段,其中包含‘id’、‘Title’和‘Text’字段。在我的Component-post_section.php文件中,我有以下php:

<?php if( have_rows('paragraph') ): ?>
<?php while( have_rows('paragraph' ) ): the_row(); ?>
  <div class="container">
    <div class="row" id="<?php the_sub_field('id'); ?>">
        <h2><?php the_sub_field('title'); ?></h2>
      <?php the_sub_field('text'); ?>
    </div>
  </div>
<?php endwhile; ?>
<?php endif; ?>

这会产生以下内容,这是很好的:

但我正在尝试制作以下内容-上面是一个 accordion 引导目录,上面有两个POST_SECTION标题:

这是我的php:

<?php if( have_rows('paragraph') ): ?>
<?php while( have_rows('paragraph' ) ): the_row(); ?>
    <div id="accordion">
  <div class="card">
    <div class="card-header" id="headingOne">
      <h5 class="mb-0">
        <button class="btn btn-link" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
          Table of Contents
        </button>
      </h5>
    </div>
    <div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
      <div class="card-body">        
            <p><a href="<?php the_sub_field('id'); ?>"><?php the_sub_field('title'); ?></a></p>
      </div>
    </div>
  </div>
</div>

  <div class="container">
    <div class="row" id="<?php the_sub_field('id'); ?>">
        <h2><?php the_sub_field('title'); ?></h2>
      <?php the_sub_field('text'); ?>
    </div>
  </div>

<?php endwhile; ?>
<?php endif; ?>

然而,我得到的是:

有什么想法,我可以实现我想要的,即输出我的标题和文本字段的每一段,但只输出一个标题的目录div这样?

也许我需要为 accordion 创建一个单独的组件php文件?

谢谢你的帮助。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题