Magento Forum

   
[SOLVED] Trouble customizing category navigation
 
PolrBear
Jr. Member
 
Total Posts:  25
Joined:  2012-01-30
 

I am running Magento 1.7 with the f002 Classic theme.  By default, this theme has its category navigation structured as a single Products super-item, corresponding to the default category and containing all other categories in a dropdown.  Not understanding Magento very well yet, I’m not even sure how this is generated.  Poking around through the design files, I have concluded that the one controlling my top menu is app/design/frontend/default/f002/template/page/html/topmenu.phtml.  Here is the template default code that brings up the menu:

<?php $_menu $this->getHtml('level-top'?>
<div class="nav-container">
    <
ul id="nav">
        <
li><a href="<?php echo $this->getUrl() ?>"><?php echo $this->__('Home'?></a></li>
        <
li><a href="<?php echo $this->getUrl('') ?>"><?php echo $this->__('Products'?></a>
        
<?php if($_menu): ?>
            
<ul>
                
<?php echo $_menu ?>
            
</ul>
        
<?php endif ?>
        
</li>
        
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('menu')->toHtml(); ?>
    
</ul>
</
div>

If I understand this code correctly, the first line generates _menu using Magento’s built-in getHtml method for “level-top,” which I assume refers to the top level of category navigation.  (Though I don’t understand how this would handle multiple root categories; I tried adding one as a test, and it did not show on the frontend at all.) This menu is then manually nested under the Products menu item.

In another Magento site I’ve already done, using 1.6 and a heavily modded version of the default theme, the top nav seems to use a different template: app/design/frontend/themename/default/template/catalog/navigation/top.phtml.  (f002 has a comparable file, but it does not seem to be used for anything.) The menu-generating section of this file, which brings up all top-level categories the way I want, goes like this:

<?php $_menu $this->renderCategoriesMenuHtml(0,'level-top'?>
<?php 
if($_menu): ?>
<div class="nav-container">
    <
ul id="nav">
        
<?php $currentUrl Mage::helper('core/url')->getCurrentUrl();?>
    
</ul>
</
div>
<?php endif ?>

Again, the first line seems to be key, as it calls a method that generates a categories menu from the real top-level - i.e. all root categories and their subcategories, not just the default one.  (Actually I’d like to be able to choose any level for this menu, like all subcategories of a given category as top-level items.)

I tried transposing the code directly from the second file to the first, and of course I got an error logged:

exception 'Varien_Exception' with message 'Invalid method Mage_Page_Block_Html_Topmenu::renderCategoriesMenuHtml ...

Which I assume occurs because I am calling that method in the wrong type of block.  (As you can tell, I still don’t understand Magento blocks very well.)

I don’t know what I’m doing well enough to even articulate the question properly, but now that I’ve shown what I’ve got and what I want, perhaps someone could offer some guidance?  Any help would be greatly appreciated.

 
Magento Community Magento Community
Magento Community
Magento Community
 
PolrBear
Jr. Member
 
Total Posts:  25
Joined:  2012-01-30
 

[bump]

Anybody?

 
Magento Community Magento Community
Magento Community
Magento Community
 
PolrBear
Jr. Member
 
Total Posts:  25
Joined:  2012-01-30
 

For the record, I got it fixed. Had to go through another Magento site that worked the way I wanted.

First, in page.xml, I commented out this line inside the top.menu block definition:

<block type="page/html_topmenu" name="catalog.topnav" template="page/html/topmenu.phtml"/>

Then I added the following lines to catalog.xml, at the top of the Mage_Catalog definition:

<reference name="top.menu">
            <
block type="catalog/navigation" name="catalog.topnav" template="catalog/navigation/top.phtml"/>
        </
reference>

This shifted the top menu template to catalog/navigation/top.phtml, which I changed with the following code:

<?php $_menu $this->renderCategoriesMenuHtml(0,'level-top'?>
<?php 
if($_menu): ?>
<div class="nav-container">
    <
ul id="nav">
        
<?php $currentUrl Mage::helper('core/url')->getCurrentUrl();?>
        
<li class="home level0 nav-1 level-top<?php if ($currentUrl === Mage::helper('core/url')->getHomeUrl()):?> active<?php endif;?>"><a href="<?php echo $this->getUrl('')?>"><?php echo $this->__('Home'?></a></li>
        
<?php echo $_menu ?>
    
</ul>
</
div>
<?php endif ?>

 
Magento Community Magento Community
Magento Community
Magento Community
 
caos989
Sr. Member
 
Total Posts:  96
Joined:  2008-07-25
Linz, Austria
 

thanks PolrBear

it works also on magento 1.8

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top