Magento

eCommerce Software for Online Growth

Magento Forum

From setting up your store to managing your products, pages and promotions to generating detailed reports, the Magento User Guide empowers the user to utilize the platform for all of its vast capacity.
Available in eBook and Print formats – Download Now!!!
   
Page 1 of 2
Simple Navigation Structure
 
myfilo
Jr. Member
 
Total Posts:  12
Joined:  2008-07-12
 

I’m having trouble customizing the sidebar navigation. I’ve weeded through some other threads but most seem to be out of date (I’m running version 1.1.3)

What I need is really quite simple. Let’s say I have the following category structure:

Main Category One
>Sub Category A
>>Sub Category A1
>>Sub Category A2
>>Sub Category A3
>Sub Category B
>>Sub Category B1
>>Sub Category B2
>>Sub Category B3

I’d like all the sub categories to be displayed like this in the side column no matter where the user is within Main Category One. So the sidebar navigation does not change as the user navigates through a category, except for a ‘current category’ highlight (and, of course, the sidebar nav changes if the user changes their Main Category selection).

Does make sense? I just don’t want any of the default navigation filters… ‘Currently Shopping by’ or the category drill down. I just need all my sub categories to be statically displayed - even when a specific item is being viewed.

Let me know if anyone has any ideas - or if you need clarification.

Thanks in advance!

 
Magento Community Magento Community
Magento Community
Magento Community
 
redletter
Jr. Member
 
Avatar
Total Posts:  24
Joined:  2008-08-19
Alberta, Canada
 

I am curious about this as well…

 
Magento Community Magento Community
Magento Community
Magento Community
 
myfilo
Jr. Member
 
Total Posts:  12
Joined:  2008-07-12
 

Maybe I didn’t explain myself clearly enough…

Let’s say I have a clothing store with 2 main categories (Mens & Womens). Each of these categories has 2 levels of sub-categories. I’ve attached a screenshot of a sample category structure to help visualize it.

If the user selects Mens, they might browse to Apparel > Pants or Apparel > Suits. Basically I need the entire (two level) sub-category structure to display statically in the sidebar wherever the user is within the Mens category. I don’t want the default Magento category filter functionality which doesn’t show all the sub-categories once the user has navigated into a certain category.

Image Attachments
category-structure.png
 
Magento Community Magento Community
Magento Community
Magento Community
 
chinesedream
Enthusiast
 
Avatar
Total Posts:  971
Joined:  2007-08-31
 

it’s not a default feature, you need to hire a js programmer to customize it for you or try figure out yourself.  That is called Tree menu; accordion menu is another way of doing it

 Signature 

Latest release : Display Magento feed on WP Blog : Art Shop Premium Magento-WordPress Theme
Wellness Magento-WordPress Theme / New Green Natural living

 
Magento Community Magento Community
Magento Community
Magento Community
 
myfilo
Jr. Member
 
Total Posts:  12
Joined:  2008-07-12
 

@chinesedream: I’m not trying to replicate the Tree menu. The previous screenshot was just from the Magento category admin to help you picture the category/sub-category structure. I definitely don’t need JS tree or accordion… I just want my sub-categories to show up statically like in the following screenshot. Does that make sense?

Image Attachments
category-subnav.png
 
Magento Community Magento Community
Magento Community
Magento Community
 
redletter
Jr. Member
 
Avatar
Total Posts:  24
Joined:  2008-08-19
Alberta, Canada
 

I have discovered that to solve this problem you have to re:writing the drawItem() function in app\code\core\Mage\Catalog\Block\Navigation.php and create a custom phtml file for the new navigation.

-------------------------------------------------------------------------------------

Step One
Open app\code\core\Mage\Catalog\Block\Navigation.php and locate this block of code.

public function drawItem($category$level=0$last=false)
    
{
        $html 
'';
        if (!
$category->getIsActive()) {

            
return $html;
        
}

        $children 
$category->getChildren();
        
$hasChildren $children && $children->count();
        
$html.= '<li';
        if (
$hasChildren{
             $html
.= ' onmouseover="toggleMenu(this,1)" onmouseout="toggleMenu(this,0)"';
        
}

        $html
.= ' class="level'.$level;
        
$html.= ' nav-'.str_replace('/''-'$category->getRequestPath());
        if (
$this->isCategoryActive($category)) {
            $html
.= ' active';
        
}
        
if ($last{
            $html 
.= ' last';
        
}
        
if ($hasChildren{
            $cnt 
0;
            foreach (
$children as $child{
                
if ($child->getIsActive()) {
                    $cnt
++;
                
}
            }
            $html 
.= ' parent';
        
}
        $html
.= '">'."\n";
        
$html.= '<a href="'.$this->getCategoryUrl($category).'"><span>'.$this->htmlEscape($category->getName()).'</span></a>'."\n";
        
//$html.= '<span>'.$level.'</span>';

        
if ($hasChildren){

            $j 
0;
            
$htmlChildren '';
            foreach (
$children as $child{
                
if ($child->getIsActive()) {
                    $htmlChildren
.= $this->drawItem($child$level+1, ++$j >= $cnt);
                
}
            }

            
if (!empty($htmlChildren)) {
                $html
.= '<ul class="level' $level '">'."\n"
                        
.$htmlChildren
                        
.'</ul>';
            
}

        }
        $html
.= '</li>'."\n";
        return 
$html;
    
}

...and replace it with...

public function drawItem($category$level=0$last=false)
    
{
        $html 
'';
        if (!
$category->getIsActive()) {

            
return $html;
        
}

        $children 
$category->getChildren();
        
$hasChildren $children && $children->count();
        
$html.= '<li class="';
        
        if (
$hasChildren{
            $cnt 
0;
            foreach (
$children as $child{
                
if ($child->getIsActive()) {
                    $cnt
++;
                
}
            }
        }
        
        
if ($level == 0){
                $html
.= ' parent';
        
else if ($level == 1{
                $html
.= ' child';
        
else if ($level == 2{
                $html
.= ' grandchild';
        
}
        
        
if ($this->isCategoryActive($category)) {
            $html
.= ' active';
        
}
        
        $html
.= '">'."\n";
        
$html.= '<a href="'.$this->getCategoryUrl($category).'">
        '
.$this->htmlEscape($category->getName()).'</a>'."\n";

        if (
$hasChildren){

            $j 
0;
            
$htmlChildren '';
            foreach (
$children as $child{
                
if ($child->getIsActive()) {
                    $htmlChildren
.= $this->drawItem($child$level+1, ++$j >= $cnt);
                
}
            }

            
if (!empty($htmlChildren)) {
                $html
.= ''."\n"
                        
.$htmlChildren
                        
.'';
            
}

        }
        $html
.= '</li>'."\n";
        return 
$html;
    
}

-------------------------------------------------------------------------------------

Step Two
Create a new file with the following contents...

<?php 
/*
 * Right Side Simple Static Menu for store
 * @see Mage_Catalog_Block_Navigation
 */
?>
<div class="right-nav-container">
       <
ul id="rightNav">
               
<?php foreach ($this->getStoreCategories() as $_category): ?>
               <?php 
echo $this->drawItem($_category?>
           <?php 
endforeach ?>
       
</ul>
</
div>
Save the new file as Right.phtml in app\design\frontend\default\default\template\catalog\navigation

-------------------------------------------------------------------------------------

Step Three
Open app\design\frontend\default\default\layout\catalog.xml and locate the following code.

<reference name="right">
Directly underneath place this line of code...
<block type="catalog/navigation" name="catalog.rightnav" template="catalog/navigation/right.phtml"/>

This will call your new menu into the right sidebar, and the HTML code will look like this.

<li class="parent active">
<
a href="...">Furniture</a>
</
li>

<
li class="child">
<
a href="...">Living Room</a>
</
li>

<
li class="child">
<
a href="...">Bedroom</a>
</
li>

<
li class="parent">
<
a href="...">Electronics</a>
</
li>

<
li class="child">
<
a href="...">Cell Phones</a>
</
li>

<
li class="child">
<
a href="...">Cameras</a>
</
li>

<
li class="grandchild">
<
a href="...">Accessories</a>
</
li>

<
li class="grandchild">
<
a href="...">Digital Cameras</a>
</
li>

-------------------------------------------------------------------------------------


Style as needed with CSS and you are done!

Enjoy!

 
Magento Community Magento Community
Magento Community
Magento Community
 
myfilo
Jr. Member
 
Total Posts:  12
Joined:  2008-07-12
 

@redletter:
Thanks for sharing your work! I tried to plug it in and it does produce an html list of categories with specific classes applied (parent/child/grandchild), but it seems to produce all categories in my catalog - not just the categories from the active parent category.

It also seemed to affect the main nav in the header - did you experience any of this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
redletter
Jr. Member
 
Avatar
Total Posts:  24
Joined:  2008-08-19
Alberta, Canada
 

I have heard of the menus displaying all of the catagories and I belive I have a good handel on how to solve this issue. As for it replacing the top menu I had coded that way for my own uses. I am on my iPhone now I will post some fixes for you tomrrow.

 
Magento Community Magento Community
Magento Community
Magento Community
 
yonirad
Jr. Member
 
Total Posts:  9
Joined:  2008-08-22
 

Any updates to this? I need this badly. Thanks!

Here is a perfect example of a magento store that does what we need…

http://www.luxurylane.com/Men/Leather

 
Magento Community Magento Community
Magento Community
Magento Community
 
Steffen Rühlmann
Jr. Member
 
Avatar
Total Posts:  1
Joined:  2008-09-01
Braunschweig, Germany
 

Thx for the code snippet - i just tried this for my test shop and found a solution for showing only the child elements of the current category. Just add the following piece of code to the snippet..

public function drawItem($category$level=0$last=false{
.....
// only show child-Elements of current category
if ($hasChildren && $this->isCategoryActive($category) ){
.....
}
...
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
yonirad
Jr. Member
 
Total Posts:  9
Joined:  2008-08-22
 

Hi Steffen,

You add the code to Navigation.php? Where do you put the code?

thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Matto
Member
 
Total Posts:  38
Joined:  2008-05-17
 

Is there a way to modify this so that the only sub categories that show are the ones relevant to the main category you’ve selected?

if anyone can help it would be great as I’ve managed to implement it as a full list but need it to be more focused.

 Signature 

Unleash the Web!
http://www.essentialebizsolutions.net

 
Magento Community Magento Community
Magento Community
Magento Community
 
aneeshvs
Jr. Member
 
Total Posts:  13
Joined:  2008-10-22
 

Hi,

I cant get this working. Nothing is displayed when I use this code… anyone have the same problem?

Thanks in advance…

 
Magento Community Magento Community
Magento Community
Magento Community
 
win_
Sr. Member
 
Total Posts:  82
Joined:  2008-02-24
Cape Town, South Africa
 

guys...i am stuck between a rock and a hard place here!
i would like to use this menu for pulling out categories and then i would like to apply it to a jquery accordion menu.
however, this script pulls all of my store categories!! how can i get it so that this will only pull out the current category and it’s sub catgories?

i have tried calling getCurrentCategory() but then the script breaks..
thank you in advance,

wins

 
Magento Community Magento Community
Magento Community
Magento Community
 
int2k
Sr. Member
 
Total Posts:  242
Joined:  2008-07-28
Bandung, Indonesia
 

i solve it using custom design for every parent category
and limit the displayed category from the template

Main
-- Sub A -> layout A
----- Sub Sub A 1
----- Sub Sub A 2
-- Sub B -> layout B
----- Sub Sub B 1
----- Sub Sub B 2

 
Magento Community Magento Community
Magento Community
Magento Community
 
win_
Sr. Member
 
Total Posts:  82
Joined:  2008-02-24
Cape Town, South Africa
 

hey,

thank you for the post...but i’m not sure i understand..
can you post an example please?

thank you,
wins

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 1 of 2
 
© Copyright 2010 Varien. Magento, eCommerce software, is a trademark of Irubin Consulting Inc. DBA Varien
Privacy Policy|Terms of Service
Magento Community Count
177657 users|1132 users currently online|277216 forum posts