上篇介绍了,如何在magento左侧导航栏里显示父分类和子分类名,如果需要在magento显示指定分类的所有子分类,可以用以下的方法:
php if($category->hasChildren()) { //判断是否有子目录 $ids = $category->getChildren(); //提取子目录id清单 $subCategories = Mage::getModel('catalog/category')->getCollection(); $subCategories->getSelect()->where("e.entity_id in ($ids)"); //提取指定目录ids的上当清单 $subCategories->addAttributeToSelect('name'); //指定查找目录名称 $subCategories->load(); foreach ($subCategories AS $item) { echo " - " ; echo ''; //获取目录链接 echo $item->getName(); //获取目录名 echo "("; echo $item->getProductCount(); //获取目录下的产品数量 echo $item->getChildrenCount(); //获取目录下子目录数量 echo ")"; echo "
"; } } ?>
或者也可以用这个方法:
php if($_category->hasChildren()) { $subCategories = $_category->getChildren(); echo '
- ';
foreach ($subCategories as $item)
{
echo "
- "; echo ''; echo $item->getName(); echo ""; echo " "; } echo '
原创文章,转载请注明:转载自Web开发笔记 | Magento里显示指定分类的所有子分类
本文链接地址:https://www.magentonotes.com/display-subcategories-in-magento.html
{ 1 comment }
think you
Comments on this entry are closed.