检查类别是否在magento中具有子类别

Vis*_*rma 5 php magento magento-1.7

我有类别ID.我从这段代码中得到了id

<?php echo $current_catid=$this->getCategoryId(); ?> 
Run Code Online (Sandbox Code Playgroud)

现在我想检查这个类别是否有子类别.

如果它有孩子,它将显示子类别图像和名称和网址.

Muf*_*dal 8

如果您有current_category id,则加载类别

$category = Mage::getModel('catalog/category')->load(id);

并检查 count($category->getChildren());

其他方法适用于计数儿童

count($category->getChildrenNodes()); 

$category->getChildrenCount();
Run Code Online (Sandbox Code Playgroud)

这样您就可以检查类别是否有孩子.

getChildren() 方法为您提供子类别ID,并根据您可以获取类别图像和类别名称.


小智 5

请尝试这个,它在我的末端工作正常

<?php  
$parentCategoryId = 10;
$categories = Mage::getModel('catalog/category')->load($parentCategoryId)->getChildren();
$catArray = explode(',', $categories);
foreach($catArray as $child)
{
$_child = Mage::getModel( 'catalog/category' )->load( $child );
echo $_child->getName() . '<br />';
echo $_child->getUrl() . '<br />';
echo $_child->getDescription() . '<br />';
}
?>
Run Code Online (Sandbox Code Playgroud)