[resolved] Nested Loop: Loop 6 posts, Loop same w/ different code, Repeat (6 posts)

  1. S3nd41
    Posted 4 years ago #

    Hi guys,

    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.

    Can anyone give me some pointers on how this can be accomplished? I tried searching the forums but the solutions are really specific and I'm not sure how to adapt them.


  2. Michael
    Forum Moderator
    Posted 4 years ago #


    you might need to use rewind_posts() http://codex.wordpress.org/Function_Reference/rewind_posts after each loop; and possibly use the 'offset' parameter for the query http://codex.wordpress.org/Class_Reference/WP_Query
    and all of that in a foreach or while loop ...

    just checking: you mean:

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

    are you working with a particular theme?

  3. S3nd41
    Posted 4 years ago #

    No, I'm building my custom theme.
    I've found some code that I've adapted and so far I've managed to get the loop to repeat twice on the first 6 posts, but after those first 6 it simply loops the remaining posts one time.

    Here's the code:


    The problem is that the second loop is only looping once after the first one prints the first 6 posts, how could I adapt this so that the second loop executes everytime?

    [No bumping. If it's that urgent, consider hiring someone.]

  4. Michael
    Forum Moderator
    Posted 4 years ago #

    you need to reset the $counter or check for a multiple of 6 with some code like if( $counter%6 == 0 )

  5. S3nd41
    Posted 4 years ago #

    It's not urgent but somewhat like 90% of the threads I create/participate in remain unanswered, (either general threads or plug-in support requests). No point in creating a forum if there's no actual participation from the community, I think. That put, thanks for the tip!

  6. S3nd41
    Posted 4 years ago #

    Managed to get a working piece of code with help from:

    Here's the final result:
    if someone else wants to do something like this.

Topic Closed

This topic has been closed to new replies.

About this Topic