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; ?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句