以下代码在一行中显示3篇文章,该行中的类项目处于活动状态。。但是,如何在自定义帖子类型类项目中显示其他帖子,以便旋转木马滑动以显示一行中的其他3篇帖子,如上图所示。。
<?php
$args = array( \'post_type\' => \'testimonial\',\'numberposts\' => 3 );
$lastposts = get_posts( $args );
$index = 0;?>
<div class="carousel-reviews broun-block">
<div class="container">
<div id="carousel-reviews" class="carousel slide testi" data-ride="carousel">
<div class="carousel-inner">
<div class="item active">
<?php foreach($lastposts as $post) : setup_postdata($post); ++$index; ?>
<div class="col-md-4 col-sm-6">
<div class="block-text rel zmin">
<p><?php the_content();?></p>
<ins class="ab zmin sprite block"></ins>
</div>
<div class="person-text rel">
<a title="" href="#"><?php the_title();?></a>
<i><?php the_field(\'country\');?></i>
</div>
</div>
<?php endforeach; ?>
</div>
使用while
<?php
$args = array(\'post_type\' => \'testimonial\',
\'posts_per_page\' =>-1,
\'caller_get_posts\'=> 3,
);
$the_query = new WP_Query($args);?>
<?php if ( $the_query->have_posts() ):?>
<?php $j = 0; ?>
<div class="carousel-reviews broun-block">
<div class="container">
<div id="carousel-reviews" class="carousel slide testi" data-ride="carousel">
<div class="carousel-inner">
<?php while ($the_query->have_posts()):$the_query->the_post();?>
<?php if($j == 0): ?>
<div class="item active">
<div class="col-md-4 col-sm-6">
<div class="block-text rel zmin">
<p><?php the_content();?></p>
<ins class="ab zmin sprite block"></ins>
</div>
<div class="person-text rel">
<a title="" href="#"><?php the_title();?></a>
<i><?php the_field(\'country\');?></i>
</div>
</div>
</div>
<?php else: ?>
<div class="item ">
<div class="col-md-4 col-sm-6">
<div class="block-text rel zmin">
<p><?php the_content();?>
<ins class="ab zmin sprite block"></ins>
</div>
<div class="person-text rel">
<a title="" href="#"><?php the_title();?></a>
<i><?php the_field(\'country\');?></i>
</div>
</div>
</div>
<?php endif; ?>
<?php $j++; ?>
<?php endwhile; endif; ?>
</div>
<a class="left carousel-control" href="#carousel-reviews" role="button" data-slide="prev">
<span class="fa fa-arrow-circle-left"></span>
</a>
<a class="right carousel-control" href="#carousel-reviews" role="button" data-slide="next">
<span class="fa fa-arrow-circle-right"></span>
</a>
</div>
</div>
</div>
SO网友:iguanarama
A.div
具有class="item"
用于每个传送带幻灯片。但现在你的foreach
循环在div内部,而不是外部,所以您的所有帖子都将放在一张幻灯片中。
所以只需将该位更改为:
<div class="carousel-inner">
<?php foreach ($lastposts as $post) : setup_postdata ($post); ++$index; ?>
<div class="item<?php if ($index == 1) { echo \' active\'; } ?>">
// Your post goes here
</div> <!-- item -->
<?php endforeach; ?>
</div> <!-- carousel-inner -->
最后,更改顶部的查询,以在旋转木马中获得您想要的任意多个帖子,例如10篇:
$args = array( \'post_type\' => \'testimonial\',\'numberposts\' => 10 );