magento logo

Magento: List categories which have the option "Include in navigation menu" set to "No"

The following source code came in handy for me, when I decided I wanted to show only the top level category in the top navigation menu of a magento store, and only show the child categories in a page whenever the top level category is clicked. This is very useful if one of your top categories contains a lot of subcategories, that will create a giant list in the drop-down menu when the visitor hovers over it.

First you have to set the sub categories as active in the magento administrator panel, but the option “Include in navigation menu” should remain switched off. Then you use the following source code in a magento template, I used the “view.phtml”.

<?php
$_category  = $this->getCurrentCategory();
$collection = Mage::getModel('catalog/category')
->getCategories($_category->entity_id, 0, false, false,false );
$helper = Mage::helper('catalog/category');
?>

<ul>
<?php foreach ($collection as $cat):?>
<?php if($_category->getIsActive()):?>
<?php
$cur_category = Mage::getModel('catalog/category')->load($cat->getId());
$_img = $cur_category->getImageUrl();
?>
<li>
<a href="<?php echo $helper->getCategoryUrl($cur_category); ?>">
<img src="<?php echo $_img; ?>" title="$cur_category->getName()"/>
<cite> <?php echo $cur_category->getName(); ?> </cite>
</a>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
Panagiotis

Written By

Panagiotis (pronounced Panayotis) is a passionate G(r)eek with experience in digital analytics projects and website implementation. Fan of clear and effective processes, automation of tasks and problem-solving technical hacks. Hands-on experience with projects ranging from small to enterprise-level companies, starting from the communication with the customers and ending with the transformation of business requirements to the final deliverable.