如何在 drupal 7 中自定义 theme_menu_tree?

How to customise theme_menu_tree in drupal 7 ?

我已经在我的 template.php 中尝试了这段代码,drupal 开发人员在很多示例中都使用了这段代码,但是当我打印出 $variables 数组时,它不包含任何名为 'tree'。我只需要将 ul li 标签添加到我的菜单块,但

function atsubtheme_menu_tree(&$variables) {
return '<ul class="nav">' . $variables['tree'] . '</ul>';
}

这就是我使用以下代码在 page.tpl 上呈现菜单的方式,该代码在 drupal 菜单的主菜单下有一个链接列表

  <nav id="menu">
     <h2>Menu</h2>
     <?php print render($page['menu_bar']); ?>
  </nav> 

我只需要 ul li 标签中的渲染菜单。

是的,我也受够了菜单 drupal 渲染器,这就是为什么我更喜欢编写自己的渲染器(在 page.tpl.php 中):

<ul class="nav">
<?php
    $mymenu = menu_tree('main-menu'); 
    foreach($mymenu as $item){ 
        if(!empty($item['#title'])){
            $attributes = array('class'=>array('all', 'my', 'classes'), 'id'=>'an-eventual-id');
            print '<li>'.l($item['#title'],$item['#href'],array('attributes'=>$attributes)).'</li>';
        }
    }
?>
</ul>

我遇到的更简单的方法

function YOURTHEMENAME_menu_tree($variables) {
return '<ul class="mycustmenu">' . $variables['tree'] . '</ul>';
//wrapping the menu in ul tags  
} 

function YOURTHEMENAME_menu_link($variables) {

$element = $variables['element'];
$sub_menu = '';

if ($element['#below']) {
$sub_menu = drupal_render($element['#below']);
//if your menu has a sub menu
}

$output = l($element['#title'], $element['#href'],$element['#localized_options']);             
return '<li>' . $output . $sub_menu . "</li>\n";
//wrapping each list item in li tags
}