getting all top and sub categories in magento

place this code in you top.phtml (\app\design\frontend\base\default\template\catalog\navigation)

<?php $_helper = Mage::helper(‘catalog/category’) ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry(‘current_category’) ?>
<div id=”navMainWrap”>
<?php if (count($_categories) > 0): ?>
<ul id=”navMain”><?php foreach($_categories as $_category): ?>
<li class=”navLevel1″ id=”navJewelry”>
<a class=”navLevel1Link” href=”<?php echo $_helper->getCategoryUrl($_category) ?>”>
<?php echo $_category->getName() ?>
<?php $_category = Mage::getModel(‘catalog/category’)->load($_category->getId()) ?>
<?php $_subcategories = $_category->getChildrenCategories() ?>
<?php if (count($_subcategories) > 0): ?>
<div class=”navSubWrap”>
            <div class=”navSub clearFix”>
                <ul class=”col1 clearFix”>
<li><p class=”colHead”>
Shop by Category</p>
<?php foreach($_subcategories as $_subcategory): ?>
<a href=”<?php echo $_helper->getCategoryUrl($_subcategory) ?>”>
<?php echo $_subcategory->getName() ?>
<?php endforeach; ?>           </ul>
<div class=”navSubBnr”>
<?php endif; ?>
<?php endforeach; ?>   </ul>
<?php endif; ?>

Leave a Comment

Your email address will not be published. Required fields are marked *