Reputation: 51
I'm using Hellowired theme, top navigation links are displayed in side bar. Instead I want subcategories of a specific category(ID 3) to be displayed in sidebar. Please keep in mind active inactive status should work when user navigates through links.
Here is the code in 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>
Help appreciated. Thank you in advance.
Upvotes: 0
Views: 561
Reputation: 2284
The '3' in load(3) is the category 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>';
}
}
}
}
Upvotes: 2