获取父类别和所有子子类别

获取父类别和所有子子类别

本文介绍了Magento-获取父类别和所有子子类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类别,有2个子类别.在每个类别中,有5个子类别.

I have a single category, that has 2 subcategories. Within each of these categories, are 5 subcategories.

是否可以获取所有这10个子类别的列表?

Is there a way to get a list of all of these 10 sub-sub-categories?

谢谢

类似这样的东西:

  Main Category
       Sub_Cat_1
            Cat_1
            Cat_2
            Cat_3
       Sub_Cat_2
            Cat_4
            Cat_5
            Cat_6

  Wanting output like:

  Cat_1
  Cat_2
  Cat_3
  Cat_4
  Cat_5
  Cat_6

谢谢

推荐答案

弄清楚了:

$cat = Mage::getModel('catalog/category')->load(24);
$subcats = $cat->getChildren();

foreach(explode(',',$subcats) as $subCatid)
{
  $_category = Mage::getModel('catalog/category')->load($subCatid);
  if($_category->getIsActive()) {
    $sub_cat = Mage::getModel('catalog/category')->load($_category->getId());
    $sub_subcats = $sub_cat->getChildren();
    foreach(explode(',',$sub_subcats) as $sub_subCatid)
    {
          $_sub_category = Mage::getModel('catalog/category')->load($sub_subCatid);
          if($_sub_category->getIsActive()) {
              echo '<li class="sub_cat"><a href="'.$_sub_category->getURL().'" title="View the products for the "'.$_sub_category->getName().'" category">'.$_sub_category->getName().'</a></li>';
          }
     }
  }
}

感谢您的光临!

这篇关于Magento-获取父类别和所有子子类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 08:58