我正在尝试构建一个内容滑块,以便每张幻灯片包含 8 个图像。为此,我需要在我的 WP 查询中每 4 个帖子添加“row-fluid”类,每 8 个帖子添加“slide”类。
我试图实现的 HTML -
<div class="coda-slider" id="slider-id">
<div class="slide">
<div class="row-fluid">
<div class="span3">
<img src="...">
</div>
<div class="span3">
<img src="...">
</div>
<div class="span3">
<img src="...">
</div>
<div class="span3">
<img src="...">
</div>
</div><!-- /row-fluid -->
<div class="row-fluid">
<div class="span3">
<img src="...">
</div>
<div class="span3">
<img src="...">
</div>
<div class="span3">
<img src="...">
</div>
<div class="span3">
<img src="...">
</div>
</div><!-- /row-fluid -->
</div><!-- /slide -->
<div class="slide">
<div class="row-fluid">
<div class="span3">
<img src="...">
</div>
<div class="span3">
<img src="...">
</div>
<div class="span3">
<img src="...">
</div>
<div class="span3">
<img src="...">
</div>
</div><!-- /row-fluid -->
<div class="row-fluid">
<div class="span3">
<img src="...">
</div>
<div class="span3">
<img src="...">
</div>
<div class="span3">
<img src="...">
</div>
<div class="span3">
<img src="...">
</div>
</div><!-- /row-fluid -->
</div><!-- /slide -->
</div><!-- /coda-slider -->
我的查询无法正常工作 -
<?php
$args = array( 'post_type' => 'video', 'posts_per_page' => 10,);
$the_query = new WP_Query( $args );
echo '<section id="our-clients">';
echo '<div class="coda-slider" id="slider-id">';
$i = 1;
echo '<div class="slide">';
echo '<div class="row-fluid">';
if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post();
echo '<div class="span3">';
the_post_thumbnail();
echo '</div>';
if($i % 8 == 0) {echo '</div><div class="slide">';}
elseif($i % 4 == 0) {echo '</div><div class="row-fluid">';}
$i++; endwhile; endif;
echo '</div>'; //row-fluid
echo '</div>'; //slide
echo '</div>'; //coda-slider
echo '</section>';
查询打印的内容 -
php 为每 8 个帖子添加一个“幻灯片”类,但第一个“幻灯片”类没有正确关闭。这可能听起来很令人困惑,所以如果您需要更多信息,请告诉我。
感谢您的帮助!