在opencart中获取第三级类别 [英] get third level category in opencart

查看:69
本文介绍了在opencart中获取第三级类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在OpenCart类别模块中进入foreach第三级, 这是仅生成2级类别的代码,请帮助并进行修改,以使其达到3级:

I want to foreach third level in OpenCart category module, here is code which only generates 2 level category, please help and modify so that it will genarate third level:

<ul id="menu">
    <?php foreach ($categories as $category) { ?>
    <li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
      <?php if ($category['children']) { ?>
        <?php for ($i = 0; $i < count($category['children']);) { ?>
        <ul>
          <?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 } ?>
        </ul>
        <?php } ?>
      <?php } ?>
    </li>
    <?php } ?>
  </ul>

推荐答案

您可以尝试一下,它虽然不优雅,但应该可以工作:

You could try this, it's not elegant but should work:

    <ul id="menu">
    <?php foreach ($categories as $category) : 
        echo '<li><a href="'.$category['href'].'">'.$category['name'].'</a>';
        if (!empty($category['children'])) : 
            echo '<ul>';
            foreach ($category['children'] as $category_level2) :
                echo '<li><a href="'.$category_level2['href'].'">'.$category_level2['name'].'</a>';
                if (!empty($category_level2['children'])) :
                    echo '<ul>';
                    foreach ($category_level2['children'] as $category_level3) :
                        echo '<li><a href="'.$category_level3['href'].'">'.$category_level3['name'].'</a></li>';
                    endforeach;
                    echo '</ul>';
                endif;
                echo '</li>';
            endforeach;
            echo '</ul>';
        endif;
        echo '</li>';
    endforeach;
    echo '</ul>';
    ?>

这篇关于在opencart中获取第三级类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆