1
我有两个环路与排序依据随机的(所有的工作好),但我想说明每个循环同一职位, 例子:我有交1至10; 循环1显示帖子1 2和3; 环2需要显示同一职位1 2和3,我的代码是:2循环随机和同一职位的WordPress
<div class="col-md-12" data-wow-delay="0.2s">
<div class="carousel slide" data-ride="carousel" id="quote-carousel">
<!-- Bottom Carousel Indicators -->
<ol class="carousel-indicators">
<?php
$args = array(
'post_type' => 'testimonials',
'orderby' => 'rand',
'posts_per_page' => 3);
$loop = new WP_Query($args);
$i = 0;
while ($loop->have_posts()) : $loop->the_post();
$avatar_testimonials = get_field('avatar-testimonials');
?>
<li data-target="#quote-carousel" data-slide-to="<?php echo $i; ?>" class="<?php if ($i == 0) echo 'active'; ?>"><img class="img-responsive" alt="<?php echo the_title(); ?>" src="<?php if ($avatar_testimonials) {echo $avatar_testimonials['url'];} else {the_post_thumbnail_url('thumbnail');} ?>" alt=""></li>
<?php $i++; endwhile; ?>
</ol>
<!-- Carousel Slides/Quotes -->
<div class="carousel-inner text-center">
<?php
$args = array(
'post_type' => 'testimonials',
'orderby' => 'rand',
'posts_per_page' => 3);
$loop = new WP_Query($args);
$i = 0;
while ($loop->have_posts()) : $loop->the_post();
?>
<!-- Quote 1 -->
<div class="item <?php if ($i == 0) echo 'active'; ?>">
<blockquote>
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
<?php echo the_excerpt(); ?>
<small><a href="<?php echo the_permalink(); ?>" title="<?php echo the_title(); ?>"><?php echo the_title(); ?></a></small>
</div>
</div>
</blockquote>
</div>
<?php $i++; endwhile; wp_reset_postdata(); ?>
</div>
</div>
</div>
不要使用两个查询 - 使用一个,并循环两次结果。 https://codex.wordpress.org/Function_Reference/rewind_posts – CBroe