0
votes

Alright, so I've been working with Magento for about 1-2 months, not too excited about it, but still trying to learn.

I've managed to install a nice Template theme for someone, and I'm currently tweaking to make it work "right".

But, I have a bit of a weird issue... firstly, my Template doesn't show root categories in the top nav, just lists the first sub categories. This is fine.

I go into a sub category, and I can see the subcategories in the left block. But when I click on one of the sub-sub-categories, the left block doesn't display any categories at all.

I can figure out that this is default behavior, because the sub-sub category I'm in has no sub-sub-sub categories. But, I was wondering, does anyone know of a good way to, when you're in a grandchilded category, to show all the categories in the main base?

EX:
Default Category (Not seen)
  Cat 1 (Shown in top nav)
    Sub Cat 1
    Sub Cat 2
  Cat 2 (Shown in top nav)
    Sub Cat 1
    Sub Cat 2
  Cat 3 (Shown in top nav)
    Sub Cat 1
    Sub Cat 2

Say for example I click on Sub Cat 2, in the Cat 3 location, could I have magento display ALL the children from the 2nd level? In this example, Cat 3 would be shown, with all it's sub-categories as well, almost as if I had clicked on just Cat 3.

I hope I explained this well, I'm about as confused with Magento as the next person...

(Here's the bit before the foreach loop to write the categories in my template file. Anyway to throw a getParent() kind of a deal in here so it always loads the 'top' category?)

<?php $_categories=$this->getCurrentChildCategories(); ?>

<?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?>

<?php if($_count): ?>
3

3 Answers

2
votes

Ok. I had a look at both of the answers provided, however, neither of them actually went the direction I was looking.

They were good in both their own accord, however, I stumbled upon something that gave me a better clue, and I programmed this snippy:

// Get the current category's path, in array.
// Ex: [0] => '20', [1] => '4'
$_categorypath = $this->getCurrentCategoryPath();

// Use Mage to get a requested Category from the category path from above.
// (The last int in the array is the top-most category, so size-1 gets last int id)
$_parent_category = Mage::getModel('catalog/category')->load($_categorypath[count($_categorypath)-1]);

// Call the children categories from the loaded category
$_categories=$_parent_category->getChildrenCategories();

// Follow the rest of the loop... Success! No "Current/Active" handler yet.. 
$_count = is_array($_categories)?count($_categories):$_categories->count();

if($_count):
// ( Run your foreach code here, complete with html formatting)

I hope this helps someone else in the future, who is looking for a similar feature.

0
votes

There is a vertical navigation extension which gives you more choice over what is shown. It doesn't have the exact behaviour you describe but is a step in the right direction and you may find it easier to modify than coming up with your own method entirely.

0
votes

The idea of the left category block is to show child categories of the current category. It sounds like you want a more static menu that always shows the same category tree. That is exactly what the top navigation does, so you can just copy the code from there, and use it as a left block. It even has .active CSS classes, so you can style it to collapse/expand subcategories based on the active category.