Show the first four categories in the menu in OpenCart

Today we provide support to Opencart forum that someone appreciates my work as we have helped him with his e-commerce designs to show the first four menu items in Opencart.

We simply changed the code and posted it on the forum and his reply was:

You, my friend, are a legend! That is exactly what I was looking for. Thank you so much! its really appreciated. I just checked out your website, some useful information on there, bookmarked 

What was the problem and how I solved it?

Solution:

<?php if ($categories) { ?>
<div id="menu">
<ul>
<?php foreach ($categories as $key=>$category) { if($key<4){ ?>
<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>
<?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 } ?>
</div>
<?php } ?>
</li>
<?php } } ?>
</ul>
</div>
<?php } ?>

Changes done are bolded.

Previous articleSchool of Computing and Technology, UML Component Modelling Assignment
Next articleBulk transfer of Products, categories and manufacturer between stores on Opencart Ecommerce Store

LEAVE A REPLY

Please enter your comment!
Please enter your name here