我正在使用OpenCart,我正在尝试渲染meta_description(用于识别漫画发布者)并使用它来制作包含子类别的下拉列表,或者给出幻觉。这是我的代码,它是当前OpenCart代码的采用版本。 ['class']是我如何抓住子类别meta_description。
基本上,第二个for语句不起作用 - 它只执行第一个。我很感激对此的任何支持。
<div class="menu">
<div id="top"></div>
<span>
<ul id="nav">
<?php foreach ($categories as $category) { ?>
<li><a href="#"><?php echo $category['name']; ?></a>
<?php if ($category['children']) { ?>
<div class="subs">
<div>
<?php for ($i = 0; $i < count($category['children']);) { ?>
<ul>
<?php $j = $i + ceil(count($category['children']) / $category['column']); ?>
<h3>DC Comics</h3>
<?php for (; $i < $j; $i++) { ?>
<?php if($category['children'][$i]['class'] == "DC Comics"){ ?>
<li>
<ul>
<?php if (isset($category['children'][$i])) { ?>
<li><a href="<?php echo $category['children'][$i]['href']; ?>"><?php echo $category['children'][$i]['name']; ?></a></li>
<?php } ?>
</ul>
</li>
<?php } ?>
<?php } ?>
<h3>Marvel</h3>
<?php for (; $i < $j; $i++) { ?>
<?php if($category['children'][$i]['class'] == "Marvel"){ ?>
<li>
<ul>
<?php if (isset($category['children'][$i])) { ?>
<li><a href="<?php echo $category['children'][$i]['href']; ?>"><?php echo $category['children'][$i]['name']; ?></a></li>
<?php } ?>
</ul>
</li>
<?php } ?>
<?php } ?>
</ul>
<?php } ?>
</div>
</div>
<?php } ?>
</li>
<?php } ?>
</ul>
</span>
</div>
答案 0 :(得分:2)
使用different variables
中的loops
,code
$i
main loop
使用incremented
,inner loops
使用foreach loop
<?php foreach ($categories as $category) { ?>
<li><a href="#"><?php echo $category['name']; ?></a>
<?php if (is_array($category['children']) and isset($category['children'])) { ?>
<div class="subs">
<div>
<ul>
<?php
$li1='<li><h3>DC Comics</h3><ul>';
$li2='<li><h3>Marvel</h3><ul>';
foreach($category['children'] as $child)
{
if($child['class'] == "DC Comics")
{
$li1.='<li><a href="'.$child['href'].'">'.$child['name'].'</a></li>';
}
if($child['class'] == "Marvel")
{
$li2.='<li><a href="'.$child['href'].'">'.$child['name'].'</a></li>';
}
}
$li1.='</ul></li>';
$li2.='</ul></li>';
echo $li1;
echo $li2;
?>
</ul>
</div>
</div>
<?php } ?>
</li>
<?php } ?>
使用{{1}}之类的,
{{1}}