tags:

views:

42

answers:

1

How do I get the current (active) top level category and its subcategories??

I do not want the root category, just the highest level category and all of its subcategories.

If I am in the Women’s Category for instance:

Women 
- Apparel 
-- Shirts 
-- Pants 
- Accessories 
-- Handbags 
-- Jewelry

Even if i am looking at shirts, i would like the category tree to remain the same.

Any help would be greatly appreciated.

+2  A: 

To give the precise answer to your precise question "how to get the current category and its subcategories" :

To retrieve the current category :

$_currentCategory = $this->getCurrentCategory();

To retrieve its subcategories :

$_categories = $this->getCurrentChildCategories();

The above are working in a catalog/navigation block.

Now, to get the rendering you are speaking about, I think that a simple navigation block with a good use of CSS would do the trick.

  1. Create a navigation block, let's say in your left column :

  2. Create the template file in your template directory structure. In our example : /template/catalog/navigation/thetemplate.phtml

  3. Use this code to draw the whole categories/subcategories structure without the hassle of modifying the code (see [1] at the end of the post....)

  4. Inspect the generated code/CSS and you will see that there are all necessary CSS pointers (levelX, active...) allowing you to display or hide pieces of the categories tree and thus showing only the parts you like.

Conclusion: CSS is sufficient to do what you want to do :)

[1] Code :

<?php $_menu = ''?>
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php $_menu .= $this->drawItem($_category) ?>
<?php endforeach ?>
<?php if ($_menu): ?>
<div class="THECSS-CONTAINER">
<ul id="THECSS">
<?php echo $_menu; ?>
</ul>
</div>
<?php endif; ?>
vrnet
i tried exactly that and it didnt work for me b/c i was using 'visibility' not 'display'. thank you so much for getting me to revisit the css of it. you just saved me a massive headache
mtokoly