I'm looping through an unknown number of containers which are using the col-md-8
Bootstrap class. I want to include next to the first iteration a col-md-4
class to offer up as a sidebar.
I need to pause the loop after the first iteration include my div then carry on looping from where it left off. Is there a php pause for the foreach loop so I can achieve this.
<?php foreach ($news as $new) : ?>
<div class="col-md-8">
</div>
<?php endforeach; ?>
You can use a if-statement
<?php
$i=1;
foreach ($news as $new) : ?>
<div class="col-md-8">
</div>
<?php if($i==1):?>
<div class="col-md-4">
</div>
<?php endif;?>
<?php $i++;?>
<?php endforeach; ?>
Try this:
<?php
$len = count($news);
for ($i = 0; $i < $len; $i++) {
if ($i == 0) {
?>
<div class="col-md-4">
</div>
<?php } ?>
<div class="col-md-8">
</div>
<?php } ?>