gpt4 book ai didi

php - 获取子类别 magento

转载 作者:可可西里 更新时间:2023-10-31 22:17:15 28 4
gpt4 key购买 nike

尝试获取处于事件状态的特定类别的子项。请帮忙。我在做这件事时遇到了麻烦。我目前能够展示所有内容,但不能具体展示。非常感谢任何帮助。

$category = Mage::getModel('catalog/category')->load(2);
$category->getChildCategories();
$tree = $category->getTreeModel();
$tree->load();
$ids = $tree->getCollection()->getAllIds();

最佳答案

这里是加载事件类别的代码

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


/*Returns comma separated ids*/
$subcats = $cat->getChildren();

//Print out categories string
#print_r($subcats);

foreach(explode(',',$subcats) as $subCatid)
{
$_category = Mage::getModel('catalog/category')->load($subCatid);
if($_category->getIsActive())
{
$caturl = $_category->getURL();
$catname = $_category->getName();
if($_category->getImageUrl())
{
$catimg = $_category->getImageUrl();
}
echo '<h2><a href="'.$caturl.'" title="View the products for this category"><img src="'.$catimg.'" alt="" />'.$catname.'</a></h2>';
}
}
?>

希望这一定能帮到你。

关于php - 获取子类别 magento,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18525419/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com