我有一个显示50个徽标的forech循环。但我需要的是另一个循环,每5个图像创建一个新的div(.autogrid_wrapper .cte .block)。
<div class="autogrid_wrapper cte block">
<div class="inner">
<?php foreach($this->entries as $entry): ?>
<figure class="image_container">
<img src="<?php echo $entry->field('logo')->generate(); ?>" title="<?php echo $entry->field('name')->value(); ?>" alt="<?php echo $entry->field('name')->value(); ?>" >
</figure>
<?php endforeach; ?>
</div>
</div>
我希望你们能帮帮我。
答案 0 :(得分:3)
一个简单的计数器可以提供帮助 -
<div class="autogrid_wrapper cte block">
<div class="inner">
<?php
$i = $j = $k = 0;
foreach($this->entries as $entry):
$i++;
$class = '';
if($j === 0) {
$class = 'first';
}
$j++;
$html = '';
if($i % 5 === 0) {
$k++;
$j = ($i - (5 * $k));
$class = 'last';
$html = "</div></div>
<div class='autogrid_wrapper cte block'><div class='inner'>";
}
?>
<figure class="image_container <?php echo $class; ?>">
<img src="<?php echo $entry->field('logo')->generate(); ?>" title="<?php echo $entry->field('name')->value(); ?>" alt="<?php echo $entry->field('name')->value(); ?>" >
</figure>
<?php
echo $html;
endforeach;
?>
</div>
</div>