我正在使用Bootstrap创建一个主题,并希望使用WP中的Bootstrap选项卡功能。这是我的代码,它工作得很好。正如您在下面的代码中看到的,我对选项卡菜单使用了一个循环,对选项卡内容使用了一个循环,但我只想对这两个使用一个循环。有可能吗?提前谢谢你。
<!-- Nav tabs -->
<ul class="nav nav-tabs">
<?php
$panel_id = 1;
$args = array(
\'post_type\' => \'book\',
\'posts_per_page\' => 8,
\'orderby\' => \'date\',
\'order\' => \'ASC\',
);
$book = new WP_Query( $args );
while( $book->have_posts() ) : $book->the_post();
?>
<li<?php if ( $book->current_post == 0 ): ?> class="active"<?php endif; ?>>
<a href="#<?php echo $panel_id; ?>" data-toggle="tab"><?php the_title(); ?></a>
</li>
<?php $panel_id++; endwhile; wp_reset_postdata(); ?>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<?php
$panel_id = 1;
$args = array(
\'post_type\' => \'book\',
\'posts_per_page\' => 8,
\'orderby\' => \'date\',
\'order\' => \'ASC\',
);
$book_2 = new WP_Query( $args );
while( $book_2->have_posts() ) : $book_2->the_post();
?>
<div class="tab-pane fade<?php if ( $book_2->current_post == 0 ): ?> in active<?php endif; ?>" id="<?php echo $panel_id; ?>">
<div class="row">
<div class="col-xs-4 col-sm-2">
<?php the_post_thumbnail(\'thumbnail\', array(\'class\' => \'img-responsive img-thumbnail\')); ?>
</div>
<div class="col-xs-8 col-sm-10">
<?php the_content(); ?>
</div>
</div>
</div>