Magento – Show Parent Category in Sub-Category

category

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>
        </div>
        <?php 
            $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>';
        ?>
    </div>
</div>

Best Answer

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.

Related Topic