2017-01-30 5 views
1

Ich habe zwei Schleife mit orderby random (alle gut funktionieren), aber ich möchte den gleichen Beitrag für jede Schleife, Beispiel zeigen: Ich habe Post 1 bis 10; Schleife 1 Zeige Beitrag 1 2 und 3; Schleife 2 Notwendigkeit gleichen Beitrag 1, 2 und 3 zu zeigen, ist mein Code:2 Schleife mit zufälligen und gleichen Beitrag 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> 
+0

Verwenden Sie keine zwei Abfragen - verwenden Sie eine und wiederholen Sie das Ergebnis zweimal. https://codex.wordpress.org/Function_Reference/rewind_posts – CBroe

Antwort

1

die Sie interessieren, ich denke, es wird für Sie arbeiten.

<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 

      $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> 
+0

danke alle arbeiten 100% jetzt. – EzraMod

Verwandte Themen