我有一个while循环,它显示了50个logo。但我需要的是另一个循环,每5个图像创建一个新的div(.autogrid_wrapper .cte .block)。
<?php
$cn = 1;
while($result->next()) {
if ($cn % 5 == 0) {
?>
<div class="autogrid_wrapper cte block">
<div class="inner">
<?php } ?>
<div class="ce_card autogrid-type_cte n5 one_fifth autogrid_mode_auto autogrid <?php echo $class2; ?> <?php echo $class; ?> block">
<div class="card_wrapper">
<a class="download_image" title="<?php echo $result->name; ?>"
<div class="ce_image attribute image">
<div class="ce_image block">
<figure class="image_container">
<img src="<?php echo $imageVar->path; ?>" onerror="this.onerror=null; this.src='files/Intershop/media/images/customers/<?php echo $rest; ?>.png'" title="<?php echo $entry->field('name')->value(); ?>" alt="<?php echo $entry->field('name')->value(); ?>" >
</figure>
</div>
</div>
</a>
</div>
</div>
<div class="clear autogrid_clear"></div>
<?php if ($cn % 5 == 0) { ?>
</div>
</div>
<?php
}
$cn++;
?>
<?php } ?>我希望你们能帮助我。
发布于 2016-04-11 17:23:46
好的,在评论中问你之后,我知道你的目的是什么了。你想在第一个项目之前执行print div(.autogrid_wrapper .cte .block),然后在while遍历第五个项目之后关闭这个div,依此类推。
$cn = 1;
while($result->next()) {
if($cn % 5 == 1) {
//div(.autogrid_wrapper .cte .block)
}
// HTML wraps image
if($cn % 5 == 0) {
//print the close tag of div(.autogrid_wrapper .cte .block)
}
$cn ++;
}将这个流控制嵌入到你的代码中,我想这会起作用的。
发布于 2016-04-11 16:10:22
带着这样的希望去尝试吧,它会有所帮助
<?php
$cn = 1;
while($result->next()) {
if ($cn % 5 == 0) { //check if number is divided by 5 like 5,10,15 etc
//new div'
}
YOUR HTML
if ($cn % 5 == 0) {
//close div'
}
$cn++;
} ?>https://stackoverflow.com/questions/36543002
复制相似问题