Advertisement
S3nd41

Loop Twice

Jan 17th, 2012
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. <?php
  2.     // First query
  3.     $my_query = new WP_Query;
  4.     $my_query->query( array( 'post_type' => '' ) );
  5.  
  6.     // If first query have posts
  7.     if( $my_query->have_posts() ) :
  8.  
  9.         $count = 0;
  10.  
  11.         // While first query have posts
  12.         while ($my_query->have_posts()) : $my_query->the_post();
  13.  
  14.             // Setup vars
  15.             $count++;
  16.             $incr_number = get_post_meta( $post->ID,'incr_number',true);
  17.         ?>
  18.  
  19.         <!-- start post -->
  20.  
  21. THE CODE FOR THE FIRST GROUP OF POSTS GOES HERE
  22.  
  23.          <!-- End post div -->
  24.  
  25.             <?php
  26.             // If count is equal to 6
  27.             if( $count == 6 ) :
  28.  
  29.                 // Second query
  30.                 $my_second_query = new WP_Query;
  31.                 $my_second_query->query( array( 'posts_per_page' => '6' ) );
  32.  
  33.                 // If second query have posts
  34.                 if( $my_second_query->have_posts() ) :
  35.                 ?>
  36.  
  37.                     <?php
  38.                     // While second query have posts
  39.                     while( $my_second_query->have_posts() ) : $my_second_query->the_post();
  40.  
  41.                         // Setup vars
  42.                         $incr_number_two = get_post_meta( $post->ID, 'incr_number', true );
  43.                         ?>
  44.  
  45. THE CODE FOR THE SECOND GROUP OF POSTS GOES HERE
  46.  
  47.                         <?php
  48.                     // End second while have posts
  49.                     endwhile;
  50.                     ?>
  51.  
  52.                 <?php
  53.                 // End if second query have posts
  54.                 endif;
  55.  
  56.             // End if count is equal to 6
  57.             endif;
  58.             ?>
  59.  
  60.         <?php
  61.         // End first while have posts
  62.         endwhile;
  63.  
  64.     // End if first query have posts
  65.     endif;
  66.     ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement