Show Sibling Categories in Magento layered Navigation
Magento Tips The layered navigation in Magento is great don’t get me wrong, but occasionally you wish to tweak it to fit your needs. One such tweak is when in a deep category with no subcategories the standard behavior is for the category section to be ommitted from the left hand side, but it may be the case that you wish to show the sibling categories here to aid navigation. This can be achieved with a simply bit of code.
The file to be changed is /app/code/core/Mage/Catalog/Model/Filter/Layer/Category.php so copy this into your /app/code/local folder and amend the function “_getItemsData” with the below.
$categoty = $this->getCategory();
/** @var $categoty Mage_Catalog_Model_Categeory */
$categories = $categoty->getChildrenCategories();
/** siblings code below ***/
if(!$categories->count())
{
$categories= $categoty->getParentCategory()->getChildrenCategories();
} else {
$this->getLayer()->getProductCollection()->addCountToCategories($categories);
}
/** end of display siblings code **/
$data = array();
What we do here is check if there are and child categories and if not we then get the child categories of the parent instead. Note the addCountToCategories function has been moved within the else, this needs to be done other wise only the active category will be displayed (as the others are filtered out).
I did this on an old installation ( Magento 1.5.1 ) and haven’t had chance to test on 1.6 or 1.7 but the theory should be the same.