Skip to main contentSkip to footer

Show the first four categories in the menu in OpenCart

Rupak Nepali
Share:
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.

Comments

Join the conversation and share your thoughts

Leave a Comment

Your comment will be reviewed before publishing.

Be the first to comment on this post!

Innovation

Let's Make Something Amazing Together

We always provide our best creative ideas at the highest level. Tell us about your project and we will make it work.

InnovateBringing innovative solutions to complex problems
AutomateStreamlining processes through automation
DominateLeading the market with exceptional results
Build Smarter and Launch FasterEfficient development for rapid deployment