Magento has its top menu reserved for category navigation. It’s pretty solid for displaying categories, even when there is a large number of them.
In most of the cases clients want is a vertical == sidebar == category menu. so they can also put sub-categories in it like menu navigation. We can always expand on this, but in most of the cases 3 levels are more than enough for stores.
layout
app/design/frontend/base/default/layout/page.xml
or your theme’s equivalent.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
<ul> <!--?php $obj = new Mage_Catalog_Block_Navigation(); $storeCategories = $obj--->getStoreCategories(); Mage::registry('current_category') ? $currentCategoryId = Mage::registry('current_category')->getId() : $currentCategoryId=''; foreach ($storeCategories as $_category): ?> <li> <strong><!--?php echo $_category--->getName(); ?></strong> <!--?php $categoryChildren = $_category--->getChildren(); ?> <!--?php if($categoryChildren--->count()) : ?> <ul> <!--?php foreach($categoryChildren as $_categoryChild) : ?--> <!--?php $_categoryChildModel = Mage::getModel('catalog/category')--->load($_categoryChild->getId());?> <!--?php $categoryGrandchildren=$_categoryChild--->getChildren(); ?> <li> <!--?php $currentCategoryId===$_categoryChild--->getId() ? $bold="style=\"font-weight:bold\"" : $bold=''; echo ' ' . '<a rel="nofollow" href="' . $_categoryChildModel->getUrl() . '" '="" .="" $bold="">' . $_categoryChild->getName() . '(' . $_categoryChildModel->getProductCollection()->count() . ')</a>'; ?> </li> <!--?php if($categoryGrandchildren--->count()) : ?> <!--?php foreach($categoryGrandchildren as $_categoryGrandchild) : ?--> <!--?php $_categoryGrandchildModel = Mage::getModel('catalog/category')--->load($_categoryGrandchild->getId());?> <li> <!--?php $currentCategoryId===$_categoryChild--->getId() ? $bold="style=\"font-weight:bold\"" : $bold=''; echo ' ' . '<a rel="nofollow" href="' . $_categoryGrandchildModel->getUrl() . '" '="" .="" $bold="">' . $_categoryGrandchild->getName() . '(' . $_categoryGrandchildModel->getProductCount() . ')</a>'; ?> </li> <!--?php endforeach; ?--> <!--?php endif; ?--> <!--?php endforeach; ?--> </ul> <!--?php endif; ?--> </li> <!--?php endforeach ?--> </ul> |
This will tell Magento to load our template on each page that sports a layout with a right column.
template file
Create app/design/frontend/base/default/template/page/custom.phtml
with the following content:
See the below image as result: