您的位置:首页 > 其它

magento 根据分类ID或名称获取该分类下的子分类

2016-08-26 16:55 911 查看
<?php
$mo=Mage::getModel('catalog/category');
$id=13;
$mode=$mo->loadByAttribute('entity_id',$id);  这里是设置条件、根据类目实体ID 查询
//$mode=$mo->loadByAttribute('name','Electronics');
这个是 根据类目名称查询、这两个条件二选一。
if($mode->hasChildren()) {
$id = $mode->getChildren();
$subCategories = Mage::getModel('catalog/category')->getCollection();
$subCategories->getSelect()->where("e.entity_id in ($id)");
$subCategories->addAttributeToSelect('*');
$subCategories->load();
}

?>
<?php  foreach($subCategories as $cate): ?>
<li><a href="<?php echo $cate->getUrl();?>"><?=$cate['name']?></a></li>
<?php endforeach; ?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: