我正在尝试让Bootstrap的手风琴在Wordpress中运行,但我不确定我还需要在循环中添加什么。目前,它扩展了第一个面板,无论我点击哪一个,而不显示任何内容。
<div class="panel-group" id="accordian" role="tablist" aria-multiselectable="true">
<?php
$args = array(
'post_type' => 'faq_question',
'category_name' => 'order',
'posts_per_page' => -1
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="<?php the_ID(); ?>">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordian" href="#collapseOne" aria-expanded="false" aria-controls="collapseOne"><?php the_title();?></a>
</h4>
</div><!-- end panel heading -->
<div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="<?php the_ID(); ?>">
<div class="panel-body">
<p><?php the_content(); ?></p>
</div><!-- end panel body -->
</div><!-- end panel collapse -->
</div><!-- end panel default -->
<?php endwhile; wp_reset_query(); ?>
</div><!-- end panel group -->
感谢任何帮助,谢谢。
答案 0 :(得分:2)
Bootstrap 4代码,区域已关闭
<!-- Accordion Collapse Bootstrap 4 -->
<div id="accordion" role="tablist" aria-multiselectable="true">
<?php
$args = array(
'post_type' => 'question',
'posts_per_page' => -1
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<div class="card">
<div class="card-header" role="tab" id="<?php the_ID(); ?>">
<h5 class="mb-0">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse<?php the_ID(); ?>" aria-expanded="false" aria-controls="collapseOne">
<?php the_Title(); ?>
</a>
</h5>
</div>
<div id="collapse<?php the_ID(); ?>" class="collapse" role="tabpanel" aria-labelledby="heading<?php the_ID(); ?>">
<div class="card-block">
<?php the_Content(); ?>
</div>
</div>
<?php endwhile; wp_reset_query(); ?>
</div>
</div>
<!-- Accordion Collapse Bootstrap 4 -->
答案 1 :(得分:1)
我怀疑它是因为你最终得到了具有相同ID的多个div #collapse1
,所以Bootstrap
并不知道你想要崩溃的那个。尝试更改代码,以便每个可折叠面板都有一个唯一的ID,如下所示;
(我已经删除了一些额外的属性,所以我可以更容易地看到发生了什么)
<div class="panel-group" id="accordian">
<?php
$args = array(
'post_type' => 'faq_question',
'category_name' => 'order',
'posts_per_page' => -1
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="collapsed" data-toggle="collapse" data-parent="#accordian" href="#collapse<?php the_ID(); ?>" ><?php the_Title(); ?></a>
</h4>
</div><!-- end panel heading -->
<div id="collapse<?php the_ID ?>" class="panel-collapse collapse">
<div class="panel-body">
<p><?php the_Content(); ?></p>
</div><!-- end panel body -->
</div><!-- end panel collapse -->
</div><!-- end panel default -->
<?php endwhile; wp_reset_query(); ?>
</div><!-- end panel group -->
答案 2 :(得分:0)
<?php
$args = array(
'post_type' => 'Help',
'posts_per_page' => -1
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="<?php the_ID(); ?>">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordian" href="#collapse<?php the_ID(); ?>" aria-expanded="false" aria-controls="collapseOne"><?php the_title();?></a>
</h4>
</div><!-- end panel heading -->
<div id="collapse<?php the_ID(); ?>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="<?php the_ID(); ?>">
<div class="panel-body">
<p><?php the_content(); ?></p>
</div><!-- end panel body -->
</div><!-- end panel collapse -->
</div><!-- end panel default -->
<?php endwhile; wp_reset_query(); ?>
</div><!-- end panel group -->