我有一个自定义的帖子类型(公告),我正在将其放入Foundation 6.4.3的选项卡和手风琴中。分类法是选项卡标题。个人自定义帖子类型内容为手风琴。
我的问题是页面加载,没有选项卡出现。我需要添加\'is-active\'
类到第一个class="tabs-panel"
但我想不出最好的方法,因为我必须启动和停止各种循环,才能让选项卡和手风琴正常工作。
我认为我不能使用任何php计数函数,因为<div class="tabs-panel">
在<?php while
, 正当
我的代码:
<ul class="tabs" data-tabs id="example-tabs">
<?php $bulletin_types = get_object_taxonomies( \'bulletinboard\' );
foreach( $bulletin_types as $bulletin_type ) :
$terms = get_terms( $bulletin_type );
foreach( $terms as $term ) : ?>
<li class="tabs-title"><a data-tabs-target="panel-<?php echo $term->slug ;?>" href="#panel-<?php echo $term->slug ;?>"><?php echo $term->name ;?></a></li>
<?php endforeach;?>
</ul>
<div class="tabs-content" data-tabs-content="example-tabs">
<?php foreach( $terms as $term ) : ?>
<?php $bulletins = new WP_Query( array(
\'taxonomy\' => $bulletin_type,
\'term\' => $term->slug,
));?>
<?php if( $bulletins->have_posts() ): ?>
<div class="tabs-panel" id="panel-<?php echo $term->slug ;?>">
<ul class="accordion" data-accordion data-allow-all-closed="true">
<?php while( $bulletins->have_posts() ) : $bulletins->the_post();
<li class="accordion-item" data-accordion-item>
<a href="#" class="accordion-title"><?php the_title();?></a>
<div class="accordion-content" data-tab-content >
//POST CONTENT HERE
</div>
</li>
<?php endwhile; ?>
</ul>
</div>
<?php endif;?>
<?php endforeach;?>
</div>
<?php endforeach; ?>
SO网友:WebElaine
当然,你可以用计数器。只需将while循环移得更高一点。大致如下:
<ul class="tabs" data-tabs id="example-tabs">
<?php
// counter for ul.tabs
$i=0;
$bulletin_types = get_object_taxonomies( \'bulletinboard\' );
foreach( $bulletin_types as $bulletin_type ) :
$terms = get_terms( $bulletin_type );
foreach( $terms as $term ) :
// increment each one
$i++; ?>
<li class="tabs-title
<?php // only for the first one, add .is-active
if($i == 1) { echo \' is-active\'; } ?>
"><a data-tabs-target="panel-<?php echo $term->slug ;?>" href="#panel-<?php echo $term->slug ;?>"><?php echo $term->name ;?></a></li>
<?php endforeach;?>
</ul>
<div class="tabs-content" data-tabs-content="example-tabs">
<?php foreach( $terms as $term ) : ?>
<?php $bulletins = new WP_Query( array(
\'taxonomy\' => $bulletin_type,
\'term\' => $term->slug,
));?>
<?php if( $bulletins->have_posts() ):
// move the while up
while( $bulletins->have_posts() ) : $bulletins->the_post();
// reset the counter
$i=0; ?>
<div class="tabs-panel<?php // again add .is-active only for first
if($i==0) { echo \' is-active\'; } ?>" id="panel-<?php echo $term->slug ;?>">
<ul class="accordion" data-accordion data-allow-all-closed="true">
<li class="accordion-item" data-accordion-item>
<a href="#" class="accordion-title"><?php the_title();?></a>
<div class="accordion-content" data-tab-content >
//POST CONTENT HERE
</div>
</li>
<?php endwhile; ?>
</ul>
</div>
<?php endif;?>
<?php endforeach;?>
</div>
<?php endforeach; ?>
基本上,您可以在使用的任何循环之前设置计数器,就像foreach一样,然后在循环中递增计数器,这样您就可以隔离第一个项目。