Display subcategories main menu opencart

This tutorial explains how to display third level category menu opencart. For displaying the third level menus in the opencart categories we need to make some changes to the core file.

This section explains what are the changes we need to make for displaying the third level subcategories as shown below.

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

Share this Tutorial