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. <ul>
2. <!--?php
3. $obj = new Mage_Catalog_Block_Navigation();
4. $storeCategories = $obj--->getStoreCategories();
5. Mage::registry('current_category') ? $currentCategoryId = Mage::registry('current_category')->getId() : $currentCategoryId='';
6. foreach ($storeCategories as $_category):
7. ?>
8. <li>
9. <strong><!--?php echo $_category--->getName(); ?></strong>
10. <!--?php $categoryChildren = $_category--->getChildren(); ?>
11. <!--?php if($categoryChildren--->count()) : ?>
12. <ul>
13.
14. <!--?php foreach($categoryChildren as $_categoryChild) : ?-->
15. <!--?php $_categoryChildModel = Mage::getModel('catalog/category')--->load($_categoryChild->getId());?>
16. <!--?php $categoryGrandchildren=$_categoryChild--->getChildren(); ?>
17. <li>
18. <!--?php
19. $currentCategoryId===$_categoryChild--->getId() ? $bold="style=\"font-weight:bold\"" : $bold='';
20. echo ' ' . '<a rel="nofollow" href="' . $_categoryChildModel->getUrl() . '" '="" .="" $bold="">' . $_categoryChild->getName() . '(' . $_categoryChildModel->getProductCollection()->count() . ')</a>';
21. ?>
22. </li>
23. <!--?php if($categoryGrandchildren--->count()) : ?>
24. <!--?php foreach($categoryGrandchildren as $_categoryGrandchild) : ?-->
25. <!--?php $_categoryGrandchildModel = Mage::getModel('catalog/category')--->load($_categoryGrandchild->getId());?>
26. <li>
27. <!--?php
28. $currentCategoryId===$_categoryChild--->getId() ? $bold="style=\"font-weight:bold\"" : $bold='';
29. echo ' ' . '<a rel="nofollow" href="' . $_categoryGrandchildModel->getUrl() . '" '="" .="" $bold="">' . $_categoryGrandchild->getName() . '(' . $_categoryGrandchildModel->getProductCount() . ')</a>';
30. ?>
31. </li>
32. <!--?php endforeach; ?-->
33. <!--?php endif; ?-->
34. <!--?php endforeach; ?-->
35. </ul>
36. <!--?php endif; ?-->
37. </li>
38. <!--?php endforeach ?-->
39. </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: