Magento 类别显示在前端问题中
+Parent cat1
+Parent cat2
+Parent cat3
+subcat1
-subcat11
-subcat12
subcat2
subcat3
+Parent cat4
我的要求是,当您单击父 cat3
时,如何显示 subcat1
和 subact2
?
当我单击 subcat11
时,我无法显示 subcat2
、subcat3
。
我需要的是,当我单击 subcat11
或 subcat12
时,它应该显示如下所示,
subcat1
-subcat11
-subcat12
subcat2
subcat3
您能帮我吗?
我的代码如下。
$loadCategory = Mage::getModel('catalog/category')->load($currentCat->getParentId());
$subCategories = explode(',', $loadCategory->getChildren());
foreach ( $subCategories as $subCategoryId )
{
$cat = Mage::getModel('catalog/category')->load($subCategoryId);
if ($cat->getIsActive())
{
if ($currentCat->getEntityId() == $subCategoryId)
{
echo '<li ><a href="'.$cat->getURL().'">'.$cat->getName().'</a></li>';
}
}
}
+Parent cat1
+Parent cat2
+Parent cat3
+subcat1
-subcat11
-subcat12
subcat2
subcat3
+Parent cat4
My requirement is when you click the parent cat3
how can I display the subcat1
and subact2
?
When I click the subcat11
I cannot display the subcat2
, subcat3
.
What I require is when I click the subcat11
or subcat12
it should show like this below
subcat1
-subcat11
-subcat12
subcat2
subcat3
Can you help me with this?
My code is given below.
$loadCategory = Mage::getModel('catalog/category')->load($currentCat->getParentId());
$subCategories = explode(',', $loadCategory->getChildren());
foreach ( $subCategories as $subCategoryId )
{
$cat = Mage::getModel('catalog/category')->load($subCategoryId);
if ($cat->getIsActive())
{
if ($currentCat->getEntityId() == $subCategoryId)
{
echo '<li ><a href="'.$cat->getURL().'">'.$cat->getName().'</a></li>';
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
垂直导航扩展有一个灵活的选项来选择类别将显示为“根”。也许您可以使用它而不是自己编写。
The vertical navigation extension has a flexible option to choose which categories will appear as 'root'. Perhaps you can use this instead of writing it yourself.