Hi everyone,
It's me again (whoo-hoo!) with more questions (aw...). Here's what I'm trying to do:
I have some categories and sub-categories and sub-sub-categories. Ex:
Root Category
- Products Category
- Category 1
- Category 1.1
- Category 1.1.1
- Category 1.1.2
- Category 1.1.3
- Category 1.2
- Category 1.2.1
- Category 1.2.2
- Category 1.2.3
- Category 2
- Category 2.1
- Category 2.1.1
- Category 2.1.2
- Category 2.1.3
and so on...
I would like all of those categories to show up (be 'active') – except for the Root Category (which doesn't, as expected) – but I want some categories to only be text and not be anchors (links to the said category). Using the above example, I don't want an anchor on the following categories:
- Category 1
- Category 1.1
- Category 1.2
- Category 2
- Category 2.1
This is what I did: I duplicated the following file: app > code > core > Mage > Catalog > Block > Navigation.php
into this location:
app > code > local > Mage > Catalog > Block > Navigation.php
Then, I replaced this code:
$html.= ''.$this->htmlEscape($category->getName()).''."\n";
with this:
if($category->getId()=='mycategorynumber'): $html.= ''.$this->htmlEscape($category->getName()).''."\n"; else: $html.= ''.$this->htmlEscape($category->getName()).''."\n"; endif;
Obviously I'm doing something wrong because otherwise I wouldn't be writing this. It's not working, even after refreshing the cache. Then I tried replacing that same line with: $html.= ''.$this->htmlEscape($category->getName()).' testing'."\n";
to see if that was gonna change anything in my top navigation, and you guessed it: fail. big time. nothing happens. The top navigation stays the same.
So I'm guessing (emphasis on 'guessing') that I AM changing the right file, BUT: 1) I'm not placing the file in the right location. 2) $category->getId() is not how I get the category number. 3) Maybe there's some XML that I need to edit as well?
Does anyone know: 1) Where I need to place Navigation.php? 2) If my PHP correct? 3) Anything else that could help me out?
If you're still reading, thank you for still being here, and for your help.
Regards, jm
Twitter: @jmbuytaert
1 Answer
jmbuytaert says:
I found the solution:
I was doing the right thing, and changing the right file. The only problem is that I was changing the wrong function.
So let’s say you want to see category 3 in the top navigation, but you don’t want it to be a link, you do this at around line 222:
public function drawItem($category, $level=0, $last=false){
...
if($category->getId()==3): $html.= '<a class="noAnchor"><span>'.$this->htmlEscape($category->getName()).'</span></a>'."\n"; else: $html.= '<a href="'.$this->getCategoryUrl($category).'"><span>'.$this->htmlEscape($category->getName()).'</span></a>'."\n"; endif;
...
}
Hope that helped someone!
