只是想知道是否有人可以帮助我处理我的代码?
我已经为Bootstrap折叠设置了ACF中继器,它会显示,但是当我单击标题时,它们不会折叠以显示内容。
<?php if( have_rows('accordion') ): ?>
<div class="accordion" id="accordion">
<?php $i = 0; ; while ( have_rows('accordion') ) : the_row(); $i++; $tCount = $i; ?>
<div class="card">
<div class="card-header" id="heading<?php echo $tCount; ?>">
<button class="btn btn-link collapsed" type="button" data-toggle="collapse<?php echo $tCount; ?>" data-target="#collapse<?php echo $tCount; ?>" aria-expanded="false" aria-controls="collapse<?php echo $tCount; ?>"><?php the_sub_field('title'); ?></button>
</div><!--End Card Header-->
</div><!--End Card-->
<div id="collapse<?php echo $tCount; ?>" class="collapse" aria-labelledby="heading<?php echo $tCount; ?>" data-parent="#accordionExample">
<div class="card-body">
Text
</div>
</div>
<?php endwhile; ?>
</div><!--End Accordian-->
<?php else : endif; ?>
谢谢!
答案 0 :(得分:0)
我让它工作了,结果是我在错误的地方回显了一些PHP。如果有人需要该代码,则为:
<?php if( have_rows('accordion') ): ?>
<div class="accordion" id="accordion">
<?php $i = 0; ; while ( have_rows('accordion') ) : the_row(); $i++; $tCount = $i; ?>
<?php
$field_accordion = get_sub_field_object('accordion_background_colour');
$value_accordion = $field_accordion['value'];
$label_accordion = $field_accordion['choices'][ $value_accordion ];
?>
<div class="card accordion-<?php echo $value_accordion; ?>-background">
<div class="card-header" id="heading<?php echo $tCount; ?>">
<button class="btn btn-link collapsed" type="button" data-toggle="collapse" data-target="#collapse<?php echo $tCount; ?>" aria-expanded="false" aria-controls="collapse<?php echo $tCount; ?>">
<h4><?php the_sub_field('title'); ?> <i class="fa fa-arrow-down" aria-hidden="true"></i></h4>
</button>
</div><!--End Card Header-->
</div><!--End Card-->
<div id="collapse<?php echo $tCount; ?>" class="collapse" aria-labelledby="heading<?php echo $tCount; ?>" data-parent="#accordion">
<div class="card-body">
Text
</div>
</div>
<?php endwhile; ?>
</div><!--End Accordian-->
<?php else : endif; ?>