Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 :)

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

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>
share|improve this answer
    
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 Nov 11 '11 at 15:37
1  
answer edited; moved position and adjusted conditioanal code –  Michael Nov 11 '11 at 17:29
    
Thank you guys, very much cheers :) –  Jezthomp Nov 14 '11 at 12:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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