views:

10

answers:

1

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  A: 

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>
vrnet
I dont know if this makes any sense to me, but that did it. Thanks man!
russjman
You're very welcome. Have fun!The block name being the same for both blocks (actually the same block called/displayed twice), Magento injects the last template in the uniquely-identified* block thus --> the same block name is displayed twice with the last template injected (left_parent_category.phtml)*sorry if this is not correct English...
vrnet