Hi, folks, this is a very quick tutorial, which let you know how to create a category navigation in Magento website. If you want to create a Magento categories based navigation, then keep your close attention in this tutorial.
Copy the below code snippet and paste it into catalog/navigation or paste it into catalog/navigation/left.phtml file if want to add navigation in the left menubar.
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 | <div id="leftnav"> < ?php $helper = $this->helper('catalog/category') ?> < ?php $categories = $this->getStoreCategories() ?> < ?php if (count($categories) > 0): ?> <ul id="leftnav-tree" class="level0"> < ?php foreach($categories as $category): ?> <li class="level0<?php if ($this->isCategoryActive($category)): ?> active< ?php endif; ?>"> <a href="<?php echo $helper->getCategoryUrl($category) ?>"><span>< ?php echo $this->escapeHtml($category->getName()) ?></span></a> < ?php if ($this->isCategoryActive($category)): ?> < ?php $subcategories = $category->getChildren() ?> < ?php if (count($subcategories) > 0): ?> <ul id="leftnav-tree-<?php echo $category->getId() ?>" class="level1"> < ?php foreach($subcategories as $subcategory): ?> <li class="level1<?php if ($this->isCategoryActive($subcategory)): ?> active< ?php endif; ?>"> <a href="<?php echo $helper->getCategoryUrl($subcategory) ?>">< ?php echo $this->escapeHtml(trim($subcategory->getName(), '- ')) ?></a> </li> < ?php endforeach; ?> </ul> <script type="text/javascript">decorateList('leftnav-tree-< ?php echo $category->getId() ?>', 'recursive')</script> < ?php endif; ?> < ?php endif; ?> </li> < ?php endforeach; ?> </ul> <script type="text/javascript">decorateList('leftnav-tree', 'recursive')</script> < ?php endif; ?> </div> |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: magenot navigation, magento navbar, magento tutorial