In the following while loop, each div item is wrapped in a li.
<php while (condition){
<li><div>Item</div></li>
<?php } ?>
In the above loop, I want to to wrap 2 div items inside a li, so that I can get similar output:
<li>
<div>Item</div>
<div>Item</div>
</li>
<li>
<div>Item</div>
<div>Item</div>
</li>
<li>
<div>Item</div>
</li>
So, I am trying this, but this wraps one div inside a li and leaves other without li.
<?php
while (condition){
$i++;
if($i % 2 == 0) { echo "<li>"; }
?>
<div>Item</div>
<?php
if($i % 2 == 0) { echo "</li>"; }
} //end loop
?>
The general idea in these cases is:
$i % $itemsPerGroup == 0++$i % $itemsPerGroup == 0$i % $itemsPerGroup != 0So: