I'm using query_post to call all posts within a custom post type I have created called 'partners'.
What I would like so it to wrap the posts in a div in groups of 6's. For example:
<div class="item">
<img src="#"/>
<img src="#"/>
<img src="#"/>
<img src="#"/>
<img src="#"/>
<img src="#"/>
</div>
<!-- 6 images/posts wrapped -->
<div class="item">
<img src="#"/>
<img src="#"/>
<img src="#"/>
<img src="#"/>
<img src="#"/>
<img src="#"/>
</div>
<!-- 6 images/posts wrapped -->
This is my code so far:
<?php
query_posts('post_type=partners');
if (have_posts()) : while (have_posts()) ;
$posts = the_post();
if( $posts ): ?>
<? $lastIndex = count($posts) - 1; ?>
<? foreach($posts as $index => $post) : ?>
<? setup_postdata($post); ?>
<? if($index % 6 === 0) { ?>
<div class="item <?=$index === 0 ? 'active' : '' ?>">
<? } ?>
<div class="car-part-logo">
<? the_post_thumbnail('full', array('class' => 'img-responsive')); ?>
</div>
<? if(($index + 1) % 6 === 0 || $index === $lastIndex) { ?>
</div>
<? } ?>
<? endforeach; ?>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
However I get the following error: unexpected T_ENDWHILE
I managed to rebuild the code based on this previous question. I altered my code to work with 6 items instead of 3.