我在opencart中有以下代码
<table class="cat_lists">
<tr>
<?php foreach ($categories as $key=>$category) { ?>
<td>
<?php echo $key%2; ?>
<div class="c_menus">
<h5><?php echo $category['name']; ?></h5>
<?php if ($category['children']) { ?>
<ul>
<?php for ($i = 0; $i < count($category['children']);) { ?>
<?php $j = $i + ceil(count($category['children']) / $category['column']); ?>
<?php for (; $i < $j; $i++) { ?>
<?php if (isset($category['children'][$i])) { ?>
<li><a href="<?php echo $category['children'][$i]['href']; ?>"><?php echo $category['children'][$i]['name']; ?></a></li>
<?php } ?>
<?php } ?>
<?php } ?>
</ul>
<?php } ?>
</div>
</td>
<?php } ?>
</tr>
</table>
实际上,菜单的UI应如下图
但我的循环输出为
如何修改循环以获得所需的结果。
修改-1
这是应该转换为动态
的html<td>
<div class="c_menus">
<h5>Necklace</h5>
<ul>
<li><a href="">Beaded Necklaces</a></li>
<li><a href="">Long Necklaces</a></li>
<li><a href="">Pendant Necklaces</a></li>
<li><a href="">Statement Necklaces</a></li>
<li><a href="">Statement Necklaces</a></li>
</ul>
</div>
<div class="c_menus">
<h5>Rings</h5>
<ul>
<li><a href="">Beaded Necklaces</a></li>
<li><a href="">Long Necklaces</a></li>
<li><a href="">Pendant Necklaces</a></li>
<li><a href="">Statement Necklaces</a></li>
</ul>
</div>
</td>
<td>
<div class="c_menus">
<h5>Necklace</h5>
<ul>
<li><a href="">Beaded Necklaces</a></li>
<li><a href="">Long Necklaces</a></li>
<li><a href="">Pendant Necklaces</a></li>
<li><a href="">Statement Necklaces</a></li>
<li><a href="">Statement Necklaces</a></li>
</ul>
</div>
<div class="c_menus">
<h5>Rings</h5>
<ul>
<li><a href="">Beaded Necklaces</a></li>
<li><a href="">Long Necklaces</a></li>
<li><a href="">Pendant Necklaces</a></li>
<li><a href="">Statement Necklaces</a></li>
</ul>
</div>
</td>
答案 0 :(得分:0)
删除此行:
<?php echo $key%2; ?>
这会删除菜单顶部的0
和1
。