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() ?>
</a>
<?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>
</li>
<?php foreach($_subcategories as $_subcategory): ?>
<li>
<a href=”<?php echo $_helper->getCategoryUrl($_subcategory) ?>”>
<?php echo $_subcategory->getName() ?>
</a>
</li>
<?php endforeach; ?>           </ul>
<div class=”navSubBnr”>
                    <!–<img>–>
</div>
</div>
</div>
<?php endif; ?>
</li>
<?php endforeach; ?>   </ul>
<?php endif; ?>
</div>

Leave a Comment

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

*