WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Splitting up the output of WP_Query (7 posts)

  1. extatix
    Member
    Posted 3 years ago #

    Okay, I'm trying to do something which splits the output of WP_Query like this:

    <div id="papa">
      <div class="kid">
       10 posts
      </div><!--- kid --->
      <div class="kid"> // yes, the same div class
       10 posts
      </div><!--- kid --->
      ....
    </div><!--- papa --->

    I first tried it with get_posts, chunk_array and two times a foreach and it worked but I want to do it with a WP_Query.

    Is there any way to this?

  2. Joseph
    Member
    Posted 3 years ago #

    You don't need to split the output. Just add a counter and an IF statement:

    <div id="papa">
    <?php if (have_posts()) : ?>
    	<div class="kid">
    
    	<?php while (have_posts()) : the_post(); ++$count; ?>
    		<!-- Add your HTML -->
    	<?php if ($count % 10 == 0 && $wp_query->post_count > 10) : ?>
    
    	</div><!--- kid --->
    	<div class="kid">
    
    	<?php endif; endwhile; ?>
    
    	</div><!--- kid --->
    <?php endif; ?>
    </div><!--- papa --->
  3. extatix
    Member
    Posted 3 years ago #

    This way everything is in <div class="kid"></div>

  4. Joseph
    Member
    Posted 3 years ago #

    Isn't that what you wanted? Group every 10 posts in a div with class="kid"?

  5. extatix
    Member
    Posted 3 years ago #

    Yes, but all posts are in ONE kid. Sorry :)

  6. extatix
    Member
    Posted 3 years ago #

    I'm still not sure where this is going wrong.

  7. extatix
    Member
    Posted 3 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.