How to get all Sub-category list by a main category Id in magento

piaoling  2011-07-14 18:39:39

How to get all Sub-category list by a main category Id in magento

 

How to see all category and subcategory menu in Magento

By default there is a top.phtml file in magento which show all category and subcategory .To modify menu display style it needs to modify in core file whcih will create problem to Update magento in future,So without touching the core file we can access all category and subcategory in magento.
For that we will write the code in top.phtml file

<?php foreach ($this->getStoreCategories() as $_category): ?>
<li>
<a href="https://aniscartujo.com/webproxy/default.aspx?prx=http://xhtmlandcsshelp.blogspot.com/search/label/<?php echo $this->getCategoryUrl($_category) ?>"><?php echo $this->htmlEscape($_category->getName()) ?></a>
<?php
$_catid=$_category->getId();
$category = Mage::getModel('catalog/category')->load($_catid);
$subcategory = $category->getAllChildren(true);
array_shift($subcategory);
if($subcategory!=null)
{?>
<ul>
<?php
foreach ($subcategory as $sub)
{
$sub1 = Mage::getModel('catalog/category')->load( $sub);
?>
<li><a href="https://aniscartujo.com/webproxy/default.aspx?prx=http://xhtmlandcsshelp.blogspot.com/search/label/<?php echo $sub1->getUrl();?>"><span>
<?php echo $sub1->getName(); ?>
</span></a></li>
<?php } ?>

</ul>
<?php }?>

</li>
<?php endforeach ?>
类别 :  magento(258)  |  浏览(2977)  |  评论(0)
发表评论(评论将通过邮件发给作者):

Email: