Php 在foreach循环中使用单独的类反转第二个div集合顺序
在foreach循环中使用单独的类反转第二个div集合顺序。 它将是一个架子状的结构。我试图交替使用Php 在foreach循环中使用单独的类反转第二个div集合顺序,php,loops,foreach,opencart,Php,Loops,Foreach,Opencart,在foreach循环中使用单独的类反转第二个div集合顺序。 它将是一个架子状的结构。我试图交替使用.tl.tr类 或 我们可以使用css来对齐第二组吗 代码: 我认为这将解决这个问题,它实现了一个计数器来跟踪当前产品应该在左边还是右边 $product_counter = 0; <?php foreach ($products as $product) { ?> <?php $product_counter++; ?> <?php if(!($prod
.tl
.tr
类
或
我们可以使用css来对齐第二组吗
代码:
我认为这将解决这个问题,它实现了一个计数器来跟踪当前产品应该在左边还是右边
$product_counter = 0;
<?php foreach ($products as $product) { ?>
<?php $product_counter++; ?>
<?php if(!($product_counter%2 ==0)) { ?>
<div class="row">
<div class="shelf">
<div class="span4">
// image echo code here
</div>
<div class="span2">
// price, add to cart etc
</div>
<?php } else { ?>
<div class="span2">
// price, add to cart etc
</div>
<div class="span4">
// image echo code here
</div>
</div> <!-- shelf div closing tag -->
</div> <!-- row div closing tag -->
<?php } ?> <!-- closing else -->
<?php } ?> <!-- closing foreach-->
<!-- in case if there were odd numbers of total product, then close the row and shelf div after foreach -->
<?php if(!($product_counter%2 ==0)) { ?>
</div>
</div>
<? } ?>
$product\u计数器=0;
//图像回显代码在这里
//价格、添加到购物车等
//价格、添加到购物车等
//图像回显代码在这里
.shelf .tl {
margin-left: 58px;
}
.shelf .tr {
margin-left: -33px;
}
$product_counter = 0;
<?php foreach ($products as $product) { ?>
<?php $product_counter++; ?>
<?php if(!($product_counter%2 ==0)) { ?>
<div class="row">
<div class="shelf">
<div class="span4">
// image echo code here
</div>
<div class="span2">
// price, add to cart etc
</div>
<?php } else { ?>
<div class="span2">
// price, add to cart etc
</div>
<div class="span4">
// image echo code here
</div>
</div> <!-- shelf div closing tag -->
</div> <!-- row div closing tag -->
<?php } ?> <!-- closing else -->
<?php } ?> <!-- closing foreach-->
<!-- in case if there were odd numbers of total product, then close the row and shelf div after foreach -->
<?php if(!($product_counter%2 ==0)) { ?>
</div>
</div>
<? } ?>