Extending this code to open magento subcategories (vertical navigation)
Hey guys, I'm wondering if anyone can help me extend this bit of code-
<h3>Browse by Category:</h3>
<ul>
<?php
$obj = new Mage_Catalog_Block_Navigation();
$store_cats = $obj->getStoreCategories();
$current_cat = $obj->getCurrentCategory();
$current_cat = (is_object($current_cat) ? $current_cat->getName() : '');
foreach ($store_cats as $cat) {
if ($cat->getName() == $current_cat) {
echo '<li><a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."</a><ul>";
foreach ($obj->getCurrentChildC开发者_开发技巧ategories() as $subcat) {
echo '<li><a href="'.$this->getCategoryUrl($subcat).'">'.$subcat->getName()."</a></li>";
}
echo "</ul></li>";
} else {
echo '<li><a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."</a></li>";
}
}
?>
</ul>
Currently, this opens the subcats on a new page upon clicking(which is good). I have subcats inside subcats, but those never show up.(on the second page)
So This is as far as I'll get-
Parent
-sub
Parent
-sub
But I need :
Parent
-sub
---sub
---sub
---sub
-sub
---sub
---sub
---sub
Can anyone help? :)
Have you ever visit Fishpig website? There is an article related with that topic, maybe you you can try their solution.
Listing Categories in Magento
Old Question- I have rebuilt the navigation since then. If anyone needs help feel free to ask.
EDIT -
I found Rico's "Vertical Navigation with CSS Classes" to suit our needs best, with a little modification of the css. It worked right out of the box, and updates depending on the order of our backend categories. He did a great job in allowing the depth of the sub-categories to be opened via the control panel.
The URL can be found here. It's free, and is supported up to 1.5 :
http://www.magentocommerce.com/magento-connect/vertical-navigation-with-css-classes.html
精彩评论