4
votes

I created a custom template (mytheme/template/catalog/navigation/left_parent_category.phtml) to display the parent categories of the current category.

<?php


echo '<div class="box base-mini">';
echo '<ol>';
    $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());
    }
    $subCategories = explode(',', $loadCategory->getChildren());

    foreach ( $subCategories as $subCategoryId )
    {
        $cat = Mage::getModel('catalog/category')->load($subCategoryId);

        if($cat->getIsActive())
        {
            echo '<li><a href="'.$cat->getURL().'">'.$cat->getName().'</a></li>';
        }
    }
echo '</ol>';
echo '</div>';

?>

I am overriding the layout with a bit of xml in the child category in the magento admin:

<reference name="left">
            <block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left_parent_category.phtml"/>
</reference>

The php and xml are doing everything correctly, but for some reason it is displaying twice. I have no clue why this template would be called twice. Any help would be greatly appreciated.

PS...this is for Magento 1.3

1

1 Answers

6
votes

My guess is that your block name (catalog.leftnav) is conflicting with another block named catalog.leftnav in the layout XML. Indeed, there's a catalog.leftnav block in catalog.xml.

Try changing your block name. ie, in your child category in the magento admin :

Change from

<reference name="left">
            <block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left_parent_category.phtml"/>
</reference>

to

<reference name="left">
            <block type="catalog/navigation" name="catalog.myniceleftnav" after="currency" template="catalog/navigation/left_parent_category.phtml"/>
</reference>