0

Is it possible after a certain amount of posts to close of a list and start a new one, like so...

Particularly after 6 posts...

<ul id="carousel">
<li>  
   <ul class="inner-items">

   <li>Post content</li>
   <li>Post content</li>
   <li>Post content</li>
   <li>Post content</li>
   <li>Post content</li>
   <li>Post content</li>

   </ul>

</li>
<li>  
   <ul class="inner-items">

   <li>Post content</li>
   <li>Post content</li>
   <li>Post content</li>
   <li>Post content</li>
   <li>Post content</li>
   <li>Post content</li>

   </ul>

</li>
</ul>

Something like this but obviously it needs to count he posts, if at all possible?

   <?php $loop = new WP_Query( array( 'post_type' => 'work','posts_per_page' => '-1' ) ); ?>


   <ul id="carousel">


   <li>  

          <ul class="inner-items">
          <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

                 <li>
                 <?php the_content(); ?>        
                 <?php the_post_thumbnail( 'work-thumb' ); ?>
                 </li>

          <?php endwhile; ?>
          </ul>

   </li>


   </ul>

I'm not even sure if possible, but any help would be great thanks :)

1 Answer 1

2

You could use the following and it should do exactly what you want by checking the value of $loop->current_post.

<?php $loop = new WP_Query( array( 'post_type' => 'work','posts_per_page' => '-1' ) ); ?>
<ul id="carousel">
    <li>
        <ul class="inner-items">
        <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <?php if( $loop->current_post  && !($loop->current_post % 6)  ) : ?>
      </ul>
  </li>
  </li>
      <ul class="inner-items"> 
    <?php endif; ?>
            <li>
                <?php the_content(); ?>        
                <?php the_post_thumbnail( 'work-thumb' ); ?>
            </li>
        <?php endwhile; ?>
        </ul>
    </li>
</ul>
2
  • Thanks for looking. But it doesn't seem to work :( The first li has an ul with 2 li inside, it then closes and moves to another li with an ul and a single li which repeats.
    – Jezthomp
    Commented Nov 11, 2011 at 15:37
  • 1
    answer edited; moved position and adjusted conditioanal code
    – Michael
    Commented Nov 11, 2011 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.