Limit number of sub-categories to show at OpenCart 2

It is not recommended to change the default files of OpenCart as if you upgrade then all changes will be lost so we have seen one solution to achieve your requirement by changing the header.tpl. Open catalog/view/theme/YOUR_THEME/template/common/header.tpl
Find the following lines of code:

<?php foreach (array_chunk($category['children'], ceil(count($category['children']) / $category['column'])) as $children) { ?>
              <ul class="list-unstyled">
                <?php foreach ($children as $child) { ?>
                <li><a href="<?php echo $child['href']; ?>"><?php echo $child['name']; ?></a></li>
                <?php } ?>
              </ul>
              <?php } ?>

And replace with following lines of code:

<ul class="list-unstyled">
  <?php foreach ($category['children'] as $key=>$child) { ?>
  <?php if($key<5){ ?>
  <li><a href="<?php echo $child['href']; ?>"><?php echo $child['name']; ?></a></li>
  <?php } ?>
  <?php } ?>
</ul>

With this change, there will be only one column.

For many sub-categories, you can make multiple columns of sub-categories in OpenCart.
While inserting the category, in the data tab, insert the “Columns” value to show multiple columns. You can see examples of the “MP3 Players” category and its sub-categories in the default installation.

limit-sub-categories-opencart-menu


Previous articleComing soon products opencart free module
Next articleSteps to create custom URL to work locally Xampp localhost virtual host

1 COMMENT

  1. i want to put a limit sub-category in menu opencart 3.x
    For exempla; i have 15 sub-category but i want to show only 5 item in menu and last one will be show more
    how can i do that?

LEAVE A REPLY

Please enter your comment!
Please enter your name here