While loop with bootstrap

时间:2015-04-28 作者:JediTricks007

可以从引导程序中使用手风琴进行while循环吗?我正在尝试从高级自定义字段中使用repeater add pro附加组件制作常见问题部分。所有的问题都出现了,但他们都找到了第一个答案。我怎样才能做到这一点?

 <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">

        <?php if(get_field(\'faq_general_ht\')): ?>

                <?php while(has_sub_field(\'faq_general_ht\')): ?>

                      <div class="panel panel-default">
                        <div class="panel-heading" role="tab" id="headingTwo">
                          <h4 class="panel-title">
                            <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true">
                             <p><?php the_sub_field(\'faq_general_question_ht\') ?></p>
                            </a>
                          </h4>
                        </div>
                        <div id="collapseOne" class="panel-collapse collapse" role="tabpanel">
                          <div class="panel-body">
                             <p><?php the_sub_field(\'faq_general_answer_ht\') ?></p>
                          </div>
                        </div>
                      </div>

            <?php endwhile; ?>
        <?php endif; ?>
    </div>

1 个回复
最合适的回答,由SO网友:m4n0 整理而成

尝试使用count变量递增循环。

<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
    <?php if(get_field(\'faq_general_ht\')): ?>
           <?php $count=0; ?>
            <?php while(has_sub_field(\'faq_general_ht\')): ?>
                <div class="panel panel-default">
                  <div class="panel-heading" role="tab" id="headingTwo">
                      <h4 class="panel-title">
                       <?php echo \'<a data-toggle="collapse" data-parent="#accordion" href="#collapse\' .$count. \'"aria-expanded="true">\' ?>
                         <p><?php the_sub_field(\'faq_general_question_ht\') ?></p>
                        </a>
                      </h4>
                    </div>
                    <?php echo \'<div id="collapse\' .$count. \'" class="panel-collapse collapse" role="tabpanel">\' ?>
                      <div class="panel-body">
                         <p><?php the_sub_field(\'faq_general_answer_ht\') ?></p>
                      </div>
                    </div>
                  </div>
             <?php $count++; ?>
        <?php endwhile; ?>
    <?php endif; ?>
</div>

结束

相关推荐

Iterate through ID's in loop

我已经基于category创建了一个自定义循环,现在我想运行一个函数,将当前帖子的特定ID作为参数进行迭代。我有。。$secondary_loop = new WP_Query(array( \'category_name\' => get_the_title(), \'posts_per_page\' => 5 )); while ( $secondary_loop->have_posts() ) : $secondary_loop->the_post();&#x

While loop with bootstrap - 小码农CODE - 行之有效找到问题解决它

While loop with bootstrap

时间:2015-04-28 作者:JediTricks007

可以从引导程序中使用手风琴进行while循环吗?我正在尝试从高级自定义字段中使用repeater add pro附加组件制作常见问题部分。所有的问题都出现了,但他们都找到了第一个答案。我怎样才能做到这一点?

 <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">

        <?php if(get_field(\'faq_general_ht\')): ?>

                <?php while(has_sub_field(\'faq_general_ht\')): ?>

                      <div class="panel panel-default">
                        <div class="panel-heading" role="tab" id="headingTwo">
                          <h4 class="panel-title">
                            <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true">
                             <p><?php the_sub_field(\'faq_general_question_ht\') ?></p>
                            </a>
                          </h4>
                        </div>
                        <div id="collapseOne" class="panel-collapse collapse" role="tabpanel">
                          <div class="panel-body">
                             <p><?php the_sub_field(\'faq_general_answer_ht\') ?></p>
                          </div>
                        </div>
                      </div>

            <?php endwhile; ?>
        <?php endif; ?>
    </div>

1 个回复
最合适的回答,由SO网友:m4n0 整理而成

尝试使用count变量递增循环。

<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
    <?php if(get_field(\'faq_general_ht\')): ?>
           <?php $count=0; ?>
            <?php while(has_sub_field(\'faq_general_ht\')): ?>
                <div class="panel panel-default">
                  <div class="panel-heading" role="tab" id="headingTwo">
                      <h4 class="panel-title">
                       <?php echo \'<a data-toggle="collapse" data-parent="#accordion" href="#collapse\' .$count. \'"aria-expanded="true">\' ?>
                         <p><?php the_sub_field(\'faq_general_question_ht\') ?></p>
                        </a>
                      </h4>
                    </div>
                    <?php echo \'<div id="collapse\' .$count. \'" class="panel-collapse collapse" role="tabpanel">\' ?>
                      <div class="panel-body">
                         <p><?php the_sub_field(\'faq_general_answer_ht\') ?></p>
                      </div>
                    </div>
                  </div>
             <?php $count++; ?>
        <?php endwhile; ?>
    <?php endif; ?>
</div>

相关推荐

Increase offset while looping

我正在编写一个自定义帖子插件,它将自定义帖子分组显示为选项卡。每组4个岗位。是否可以编写一个偏移量随每次循环而增加的查询?因此,结果将是:-第一个查询显示从1到4的帖子-第二个查询显示从5到8的帖子-第三个查询显示从9到12的帖子等。 <div class=\"official-matters-tabs\"> <?php $args = array(\'post_type\' => \'official-matters\', \'showp