Pages

Wednesday 11 July 2012

How to show child categories according to parent category id in magento

According to position in admin panel
<?php
$cats = Mage::getModel('catalog/category')->load(13)->getChildrenCategories();
?>
<ul>
<?php foreach($cats as $category): ?>
    <li>
        <a href="<?php echo $category->getUrl() ?>"><?php echo $category->getName() ?></a>
    </li>
<?php endforeach; ?>
</ul>
 
 
According to category id in magento 
 
<?php
$cats = Mage::getModel('catalog/category')->load(13)->getChildren();
$catIds = explode(',',$cats);
?>
<ul>
<?php foreach($catIds as $catId): ?>
    <li>
        <?php
            $category = Mage::getModel('catalog/category')->load($catId);
            echo '<a href="' . $category->getUrl() . '">';
            echo $category->getName() . '</a>';
        ?>
    </li>
<?php endforeach; ?>
</ul>
 

No comments:

Post a Comment