Theme a custom menu with theme_menu_tree()

2019-05-28 09:17发布

问题:

I'm trying to override a custom menu output in a block so that instead of

    <ul class="menu">...</ul>

I can get

    <select name="menu title">...</select>

In Drupal 6, I could use function theme_menu_tree($tree,$menu_name="") {...} but this doesn't work in Drupal 7 with function theme_menu_tree($variables) {...}.

I've tried theme_menu_tree__mymenu($variables) {...} with no success. How do I specify a unique menu in Drupal 7?

Thanks.

回答1:

I had the same problem with overriding and correct naming of the theme_menu_tree function for a specific menu name. What I found I suppose that the correct name of your function should be: YOUR_THEMENAME_menu_tree__YOUR_MENUNAME

The name of your menu could be taken from Administration » Structure » Menus pages. It seems to me that Drupal adds word "menu" before all of the new user menus. In my case I created a menu called "Testing menu" in a theme "Mytheme" and the name of the overriding function was: mytheme_menu_tree__menu_testing_menu