How do I show on a category page in Magento only the parent category and subcategories?
When a subcategory is clicked the navigation has to stay the same.
Example: If I have
Category 1
- subcat 1
- subcat 2
- subcat 3
After clicking on any subcategory (say subcat 1), I want the same i.e :
Category 1
- subcat 1
- subcat 2
- subcat 3
What I got now:
<?php
if (Mage::registry('current_category'))
{
echo Mage::registry('current_category')->getName();
}
?>
<?php
$currentCat = Mage::registry('current_category');
if ( $currentCat->getParentId() == Mage::app()->getStore()->getRootCategoryId() )
{
// current category is a toplevel category
$loadCategory = $currentCat;
}
else
{
// current category is a sub-(or subsub-, etc...)category of a toplevel category
// load the parent category of the current category
$loadCategory = Mage::getModel('catalog/category')->load($currentCat->getParentId());
// @TODO enhance for more nested category levels to display sub-categories
}
$subCategories = explode(',', $loadCategory->getChildren());
foreach ( $subCategories as $subCategoryId )
{
$cat = Mage::getModel('catalog/category')->load($subCategoryId);
if($cat->getIsActive())
{
echo '<a href="'.$cat->getURL().'">'.$cat->getName().'</a> ';
}
}
?>
But of course this isn't working correct but I can't find a good solution so that Category 1 stays the same when I press subcat 1.
And it would be wonderful if the selected subcategory would be bold.