php - Magento 1.9: How to get Subcategories of specific Category? -


i using following block in magento cms home site:

{{block type="catalog/product_list" name="catalog_list" category_id="1420" template="catalog/product/liststart.phtml"}} 

how can output of subcategories of category_id specified in block (id 1420 in case).

so far have following code:

<?php $_category = $this->getcurrentcategory(); $collection = mage::getmodel('catalog/category')->getcategories($_category->entity_id); $helper = mage::helper('catalog/category'); ?> <div class="category-products"> <div id="carousel">     <ul class="products-in-row">         <?php $i=0; foreach ($collection $cat): ?>             <li class="item">                 <?php echo $cat->getname();?>             </li>         <?php endforeach ?>     </ul> </div> 

i'm getting subcategories of main category only.

this code may if want child category of every current category

  <?php   $layer = mage::getsingleton('catalog/layer');   $_category = $layer->getcurrentcategory();   $currentcategoryid= $_category->getid();   $children = mage::getmodel('catalog/category')->getcategories($currentcategoryid);   foreach ($children $category)   {       echo $category->getname(); // return category name        echo $category->getrequestpath(); // return category url   }   ?> 

another way:

<?php   $categoryid = 10 ;  // current category id   $category = mage::getmodel('catalog/category')->load($categoryid);   $catlist = explode(",", $category->getchildren());   foreach($catlist $cat)   {      $subcategory = mage::getsingleton('catalog/category')->load($cat);      echo $subcategory->getname();    } ?>  

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -