Using the following piece of code, or something similar in a template.php file to override the menu tree will only apply the modified class and id to sub-menus ul's.

The parent menu still has class="menu" applied to it by theme_menu_tree in menu.inc

If theme_menu_tree in menu.inc is modified, the correct information populates to all levels of the menu.

<?php
function phptemplate_menu_tree($pid = 1) {
  if ($tree = menu_tree($pid)) {
    $output .= "<ul id=\"foo\" class=\"bar\">";
    $output .= $tree;
    $output .= "</ul>\n";
    return $output;
  }
}
?>

More information and the use case can be seen on the following forum thread http://drupal.org/node/140654

Comments

drumm’s picture

Category: bug » support
Status: Active » Postponed (maintainer needs more info)

Unable to reproduce. Are you running any contributed modules which might be outputting the menu? What block is outputting the menu?

mrf’s picture

The following code outputs the menu in my page.tpl.php:

            <?php 
            $menuhtml = theme_menu_tree(50);
            print $menuhtml;
            ?> 

The site where I first noticed the problem has the following contributed modules installed. I have since had the same problem on another site, with slightly different modules.

cck/
contemplate/
devel/
front/
imagefield/
login_destination/
pathauto/
private/
search_config/
tinymce/
webform/

Thanks for your help, I really appreciate it.

drumm’s picture

There is the problem.. theme functions need to be called like theme('menu_tree', 50);.

mrf’s picture

That did the trick.

Thanks for your help.

So, for my own understanding of what was going on, was I calling the original non-modified function from menu.inc rather than the one modified in template.php with my theme_menu_tree function?

drumm’s picture

The theme() function figures out what function to call.

drumm’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)
senortim’s picture

Version: 5.1 » 6.3
Status: Closed (fixed) » Active

OK total drupal newbie here needing help:

I tried the code above in drupal 6.3 by taking it into the template.php file from the "zen" theme and saving it to my own sub-theme folder. But I'm getting a PHP error saying that "menu_itemlink()" is an undefined function.

Further, I can't find "menu_tree" anywhere in the original zen folder. So where does one make the necessary changes in this solution?

Thanks.

ainigma32’s picture

Status: Active » Fixed

Looks like senortim either gave up or figured this out on his own. Setting to fixed.

Feel free to reopen if you think that is wrong.

- Arie

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.