如何按级别显示类别?
我想在列表页面上显示当前类别的子类别(如果有),但如果没有子类别并且当前类别不是主类别,则显示相同级别的类别。
<?php
//print_r($_category); exit;
$Curr_cat_id = $_category->getEntityId();
$children = Mage::getModel('catalog/category')->getCategories($Curr_cat_id);
if($children){
foreach($children as $sub_cat)
{
$subCat = Mage::getModel('catalog/category')->load($sub_cat->getId());
?>
<a href="<?php echo $this->getUrl().$sub_cat->getRequestPath(); ?>" >
<?php echo $sub_cat->getName(); ?>
</a><br />
<?php
} // end of foreach
} // end of if
//else{
// this is where i want the same level categories if in case there are no sub-categories and also the current category is not a main category.
//}
?>
i want to display sub-categories (if any) of a current category on listing page, but if there is no sub-category and also the current category is not the main category, then display the same level categories.
<?php
//print_r($_category); exit;
$Curr_cat_id = $_category->getEntityId();
$children = Mage::getModel('catalog/category')->getCategories($Curr_cat_id);
if($children){
foreach($children as $sub_cat)
{
$subCat = Mage::getModel('catalog/category')->load($sub_cat->getId());
?>
<a href="<?php echo $this->getUrl().$sub_cat->getRequestPath(); ?>" >
<?php echo $sub_cat->getName(); ?>
</a><br />
<?php
} // end of foreach
} // end of if
//else{
// this is where i want the same level categories if in case there are no sub-categories and also the current category is not a main category.
//}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要先获取当前类别的父类别ID。然后使用父类别 id 加载产品(就像您在脚本中所做的那样)。
要实现这一目标,以下帖子应该会有所帮助
http://www.magentocommerce.com/boards/ viewthread/16357/
You need to get the parent category id of your current category first. And then load the products ( like you are doing in your script ) with the parent category id instead.
To achieve that the following post should be of help
http://www.magentocommerce.com/boards/viewthread/16357/