All right guys, I need a little help for a loop. I have a query that get's all images for my database, and I need to separate them in blocks of 6. Every 6 images, one block with div. Somethign like:
<div class='item'>
<li><img></li>
<li><img></li>
<li><img></li>
<li><img></li>
<li><img></li>
<li><img></li>
</div>
<div class='item'>
<li><img></li>
<li><img></li>
<li><img></li>
<li><img></li>
<li><img></li>
<li><img></li>
</div>
My code is for the Wordpress Pods Plugin:
<div class="carousel-inner">
<?php
$cat = new Pod("galeria"); //nome do pod
$records = $cat->findRecords("t.ID"); //listado pelo titulo e limite dos pods
?>
<?php if($records%6 == 0): echo $records;?>
<div class="item">
<?php elseif($records == 6): ?>
<div class="item active">
<?php endif; ?>
<div class="row">
<?php
while ($cat->fetchRecord()) :
$id = $cat->get_field("ID"); //pega id
$imagens = $cat->get_field("imagens"); //lista de imagens
$thumb_url = wp_get_attachment_url( get_post_thumbnail_id( $id ) );
$permalink = $cat->field('permalink');
?>
<div class="col-sm-2"><a href="<?php echo $permalink; ?>" class="thumbnail"><img src="<?php echo $thumb_url; ?>" alt="Image" class="img-responsive"></a></div>
<?php endwhile; ?>
</div><!--/row-->
<?php if($records%6 == 0): ?>
</div><!--/item-->
<?php endif; ?>
UPDATE 22/07 - 03:45
Used the code you provide and it's awesome. If someone needs it, this is my final code:
<div class="carousel-inner">
<?php
$cat = new Pod("galeria"); //the Pod name
$records = $cat->findRecords("t.ID"); //listing items by ID
$i = 0;
?>
<?php
while ($cat->fetchRecord()) :
$id = $cat->get_field("ID"); //get id
$imagens = $cat->get_field("imagens"); //list images
$thumb_url = wp_get_attachment_url( get_post_thumbnail_id( $id ) ); // the thumbnail url
$permalink = $cat->field('permalink'); // the pods permalink
?>
<?php if($i % 6 == 0): ?> // every 6 images
<div class="item <?php if( $i == 0 ){ echo 'active'; //if is the very first, add class 'active' } ?>">
<div class="row">
<?php endif; ?>
<?php $i++; ?> // increment the $i
<div class="col-sm-2"><a href="<?php echo $permalink; ?>" class="thumbnail"><img src="<?php echo $thumb_url; ?>" alt="Image" class="img-responsive"></a></div> // the <li> item
<?php if ( $i != 0 && $i % 6 == 0): ?> // close the .item div every 6 images
</div> <!--/row-->
</div><!--/item-->
<?php endif; ?>
<?php endwhile; ?>
<?php if ( $i % 6 != 0 ): ?>
</div><!--/row-->
</div><!--/item-->
<?php endif; ?>