我正在使用Hellowired主题,顶部导航链接显示在侧栏中。相反,我希望在侧边栏中显示特定类别(ID 3)的子类别。请记住,当用户浏览链接时,活动的非活动状态应该起作用。
以下是leftnav.phtml中的代码:
<div class="block block-leftnav">
<div class="block-title"><strong><span><?php echo $this->__('Shop Categories') ?></span></strong></div>
<div class="block-content">
<ul id="leftnav">
<!-- HOME BUTTON HACK -->
<?php $_anyActive = false; foreach ($this->getStoreCategories(3) as $_category) { $_anyActive = $_anyActive || $this->isCategoryActive($_category); } ?>
<li class="home <?php echo !$_anyActive ? 'active' : '' ?>"><a href="<?php echo $this->getUrl('')?>"><span><?php echo $this->__('Home') ?></span></a></li>
<!-- HOME BUTTON HACK -->
<?php foreach ($this->getStoreCategories(3) as $_category): ?>
<?php echo $this->drawItem($_category) ?>
<?php endforeach ?>
</ul>
</div>
</div>
帮助表示感谢。提前谢谢。
答案 0 :(得分:2)
load(3)中的'3'是类别ID。
$cat = Mage::getModel('catalog/category')->load(3);
$subcats = $cat->getChildren();
foreach(explode(',',$subcats) as $subCatid)
{
$_category = Mage::getModel('catalog/category')->load($subCatid);
if($_category->getIsActive()) {
$sub_cat = Mage::getModel('catalog/category')->load($_category->getId());
$sub_subcats = $sub_cat->getChildren();
foreach(explode(',',$sub_subcats) as $sub_subCatid)
{
$_sub_category = Mage::getModel('catalog/category')->load($sub_subCatid);
if($_sub_category->getIsActive()) {
echo '<li class="sub_cat"><a href="'.$_sub_category->getURL().'" title="View products for "'.$_sub_category->getName().'" category">'.$_sub_category->getName().'</a></li>';
}
}
}
}