Fabio Casolari
Fabio Casolari

Reputation: 1

Show single Magento category on sidebar

How can I show a single category tree on the sidebar?

Not a product, only the category tree.

Upvotes: 0

Views: 1223

Answers (2)

Jonathan Day
Jonathan Day

Reputation: 18702

The formal way to do this for yourself is to create a module using the Module Creator (search Magento Connect for this) and then:

Create a new phtml file with the following code:

$storeCategories = $this->getCats('my-category-url-key');
        foreach ($storeCategories as $category):
            echo '<li><a href="' . $category->getUrl() . '">' . $category->getName() . '</a></li>';
        endforeach;

Then a Block called (say) Namespace_Yourmodule_Block_Singlecat with the following code:

 public function getCats($catName)
 { 
     $parent = Mage::getResourceModel('catalog/category_collection')
                     ->addAttributeToSelect('entity_id')
                    ->addAttributeToFilter('url_key', $catName)
                    ->getFirstItem();
     return $storeCategories = Mage::getModel('catalog/category')
        ->getCategories( $parent->getId(), $recursionLevel=1, $sorted=false, $asCollection=true, $toLoad=false);
}

Then you just need to insert the following nodes into app\design\frontend\yourtheme\layout\yourmodule.xml layout file:

<reference name="left">
        <block type="yourmodule/singlecat" name="singlecat" template="path/yourfilename.phtml" />
    </reference>

Cross your fingers, pray to your deity of choice and Magento may smile upon your code :)

Upvotes: 0

clockworkgeek
clockworkgeek

Reputation: 37700

I have been using Vertical Navigation to do something similar.

Upvotes: 1

Related Questions