if ( $i % 8 == 0) {
echo '</div><!--.container--><div class="container">';
}
Mod operator returns the remainder. You can simply state $i % 8
or $i % 8 == 0
or $i % 8 === 0 as john stated
But you will need to also open the next div in your conditional depending on how you structure this. An example:
<div class="outer-container">
<div class="inner-container">
<?php
$images; // object
$i = 1;
while ( $images->have_images() ) {
echo 'content here';
//print_r($i % 8);
if ( $i % 8 == 0 && $images->total > 8) {
echo '</div><!--.inner-container--><div class="inner-container">';
}
$i++;
}
?>
</div>
</div>
Added conditional in case your images total happens to be 8 it won't create a rogue empty div.
I'm trying to understand your comment. Are you saying you have an outer container, then an inner container, and inside this inner container you want the loop you defined in the question where each group of 8 is contained in a container
div?
I added a print r in the loop you can uncomment to verify $i is doing what you want it to. By this code and the fact that $i begins at 1 you should not experience the closing div conditional prematurely.