Magento 1.9:如何获取特定类别的子类别?

Magento 1.9: How to get Subcategories of specific Category?

我在主站点的 Magento CMS 中使用以下块:

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

我怎样才能得到块中指定的 category_id 的所有子类别的输出(在本例中为 id 1420)。

到目前为止我有以下代码:

<?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 as $cat): ?>
            <li class="item">
                <?php echo $cat->getName();?>
            </li>
        <?php endforeach ?>
    </ul>
</div>

我只获取主要类别的所有子类别。

如果您想获取每个当前类别的子类别,此代码可能会有所帮助

  <?php
  $layer = Mage::getSingleton('catalog/layer');
  $_category = $layer->getCurrentCategory();
  $currentCategoryId= $_category->getId();
  $children = Mage::getModel('catalog/category')->getCategories($currentCategoryId);
  foreach ($children as $category)
  {
      echo $category->getName(); // will return category name 
      echo $category->getRequestPath(); // will return category URL
  }
  ?>

另一种方式:

<?php
  $categoryId = 10 ;  // get current category id
  $category = Mage::getModel('catalog/category')->load($categoryId);
  $catList = explode(",", $category->getChildren());
  foreach($catList as $cat)
  {
     $subcategory = Mage::getSingleton('catalog/category')->load($cat);
     echo $subcategory->getName(); 
  }
?>