I want to show my parent category and all its sub-categories, whenever I visit one of those category pages.

I want a structure like this on all the Ralph Lauren categories;

  • Ralph Lauren
    • T-shirts
    • Pants
    • Jackets

But this only shows when I visit the parent category Ralph Lauren. If I click on T-shirt it doesn't show any other categories, since Ralph Lauren T-shirts doesn't have any children.

How can I achieve that?

<div class="magicat-container">
    <div class="block">
        <div class="block-title cat_heading">
            <strong><span><?php echo Mage::registry('current_category')->getName(); ?></span></strong>
            $store_categories = $this->toLinearArray($this->getStoreCategories());
            if ($count = count($store_categories))
                echo '<ul id="magicat">';
            foreach ($store_categories as $i => $_category)
                $class = array() ;
                if ($count == 1)
                    $class[] = 'only';
                else if(!$i)
                    $class[] = 'first';
                else if ($i == $count-1)
                    $class[] = 'last';
                if (isset($store_categories[$i+1]) && $this->isCategoryActive($store_categories[$i+1]))
                    $class[] = 'prev';
                if (isset($store_categories[$i-1]) && $this->isCategoryActive($store_categories[$i-1]))
                    $class[] = 'next';
                echo $this->drawOpenCategoryItem($_category, 0, $class);
            if ($count)
                echo '</ul>';
  • are you talking about layered navigation ? Aug 11, 2014 at 9:16
  • Nope, I just want to show the same categories for the parent and child categories. So they both show Ralph Lauren and its sub-categories.
    – McKeene
    Aug 11, 2014 at 9:32
  • which page is provided as reference above ? Aug 11, 2014 at 9:57
  • is that your product/list.phtml page ? I am asking about the above code Aug 11, 2014 at 10:58
  • No the above code is the left top category block.
    – McKeene
    Aug 11, 2014 at 11:24

2 Answers 2


Ok You shoud modify the function $this->getStoreCategories()

$_current_category = Mage::registry('current_category');
$path = $_current_category->getPath(); //get the path of where you are
$ids = explode('/', $path);
//now you have something like root category/base store category/first level 
if (isset($ids[2])) { //you should add some more complex lookout
    $topParent = Mage::getModel('catalog/category')->setStoreId(Mage::app()->getStore()->getId())->load($ids[2]);
//topParent is the ralph loren category even if you are in one of its children cat

Of course this is only a start point for your coding but you should have alla elements in it.


You should modify your "menu template" in order to check the level of the current category and if it is T-Shirt Pant or Jacket you should load the parent category instead. more details are possibile only if you provide more info con you template and/ore code sample

  • I have added the code now. What may be a challenge is that when I'm on Ralph Lauren, I don't want to show its parent category, but still just Ralph Lauren and its sub-categories.
    – McKeene
    Aug 11, 2014 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.