我使用theme_menu_link来修改菜单,在这种情况下,main_menu。 Evertything按预期工作,但是我使用Menu Block在内部页面上的侧边栏中呈现主菜单的另一个实例。Drupal - 如何修改菜单中的一个实例与他们_menu_link
问题是,我只希望我的修改显示在main_menu的实例中,我用于网站的主导航,但不是在侧边栏中使用的实例中。
详情:
这是我的theme_menu_link功能
/**
* Returns custom HTML for the main navigation menu.
* Adds an HTML element to top level parent <li> elements
* to serve as a drop-down menu toggle.
*
* this also sets the HTML wrapper for sub menus, to override the above
* them_menu_tree function, which is intended for top level menus only.
*
* @param $variables
* An associative array containing:
* - element: Structured array data for a menu link.
*
* @ingroup themeable
*/
function mytheme_menu_link__main_menu($variables) {
$element = $variables['element'];
$child_menu = $element['#below'];
$sub_menu = '';
// if the current top level item has child menus (sub menus)
if ($child_menu) {
// unset the sub menu wrapper set above in mytheme_menu_tree__new_main_menu()
unset($child_menu['#theme_wrappers']);
// add opening ul tag for the sub menu wrapper to $sub_menu
$sub_menu = '<ul class="menu sub-menu">';
// iterate over each sub menu item
foreach ($child_menu as $child_menu_item){
// add sub menu item link HTML to a variable
$child_menu_output = l($child_menu_item['#title'], $child_menu_item['#href']);
// check to see if item has a title, sincle $element['#below'] returns things besides menu items
if($child_menu_item['#title']) {
// output each sub menu item's link and description, wrapped in a <li> element
$sub_menu .= '<li>' . $child_menu_output .'</li>';
} // end if shild menu item has a title
} // end foreach child menu item
// add closing ul tag for the sub menu wrapper to $sub_menu
$sub_menu .= '</ul>';
}
// output a dummy link for top level items
$output = '<a href="#" class="nolink">' . $element['#title'] . '</a>';
return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . '</li>';
}
上述函数就像我希望它在网站的主要导航工作。但是,我不希望这适用于在菜单栏的侧边栏中使用的main_menu实例。有没有一种方法有条件地使用them_menu_link基于区域或阻止菜单是bing呈现它?
没有菜单供您属性工作? https://www.drupal.org/project/menu_attributes – hyunkeln 2014-10-28 19:53:29
我见过这个模块,但它似乎没有解决我想要做的:定制菜单标记(不只是菜单项属性),但范围那些自定义为特定菜单的单个实例。不过,我的答案在下文中有效。 – 2014-10-28 23:45:50