WordPress: Nested Loop: Loop 6 posts, Loop same w/ different code, Repeat

I’m trying to get a nested loop working that will display 6 posts with a certain code, then go back, display the same 6 posts with a different code and then continue doing this until there are no more posts.

Example:

Read More
A B C D E F   
a b c d e f  
G H I J K L   
g h i j k l

So far I’ve managed to find this code:
http://pastebin.com/hBkYvy6U
but it only repeats the loop on the first 6 posts and, afterwards, it simply outputs the posts once.

Probably the second output isn’t nested correctly into the first one, can anyone help me figure this out?

Related posts

Leave a Reply

2 comments

  1. Try changing line 27 to use modulo % operator or fmod function instead of if($count == 6 )

    That should give your the expected result for all items in the list by repeating this action for every post 6 at a time (6,12,18,24,…).

    if($count % 6 ==0  && $count !=0) // should give you what you are looking for
    
    
    example of modulo and fmod use
    
    <?php
    $var1 = 5;
    $var2 = 2;
    
    echo $var1 % $var2; //Returns 1
    echo fmod($var1,$var2); //Also returns the same
    ?>
    
  2. I believe you just need to reset your count = 0 after you find that count = 6

    ie:

    // If count is equal to 6
                if( $count == 6 ) : 
                                   //reset my counter
                                   count = 0;
    
                    // Second query
                    $my_second_query = new WP_Query;
                    $my_second_query->query( array( 'posts_per_page' => '6' ) );