Question

How can I set the subcategories to be visible at all times in main navigation block (left column)? Once I start browsing the subcategories of any category, the navigation block is showing only the top categories. Example at www.valikoi.com.

Regards, Tommi

Was it helpful?

Solution

I think this will help you,

<ul class="catlist">
<?php
$obj = new Mage_Catalog_Block_Navigation();
$store_cats = $obj->getStoreCategories();
$current_cat    = $obj->getCurrentCategory();

$current_cat    = (is_object($current_cat) ? $current_cat->getName() : '');
$currentCategory = Mage::registry('current_category'); 

foreach ($store_cats as $cat) {
if ($cat->getName() == $current_cat) {
//enters and lists all main categories
echo '<li class="current">
<a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."</a>\n<ul>\n";

//get the child category of a current category  
 foreach ($obj->getCurrentChildCategories() as $subcat) {
echo '<li>
<a  href="'.$this->getCategoryUrl($subcat).'">'.$subcat->getName()."</a></li>\n";
}
echo "</ul>\n</li>\n";
} else {
//enters when a sub category is clicked and lists all main categories
echo '<li>
<a  href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."      </a></li>\n";

//this is to load the categories like in admin order
$loadCategory= Mage::getModel('catalog/category')->getCategories($currentCategory->getParentId(),0, true, true);

//below code did not work to load categories like in admin order
//$explod= $loadCategory->getChildrenCategories('position','asc');
//$subCategories = explode(',', $explod);

if (($currentCategory->getParentId() == $cat->getId()) )
{ 
//enters when a sub category is clicked and loads its parent and show its subcategories
echo '<ul class="catlist_inner">';
foreach ($loadCategory as $subCategoryId)
{


if($subCategoryId->getIsActive())
{
echo '<li>
<a href="'.$subCategoryId->getURL().'">'.$subCategoryId->getName().'</a>       </li>';
}
}
echo '</ul>';
}
}
}
?>
</ul>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top