【发布时间】:2014-10-28 19:47:20
【问题描述】:
我正在使用 theme_menu_link 来修改菜单,在本例中为 main_menu。 Evertything 按预期工作,但是我正在使用菜单块在内部页面的侧边栏中呈现主菜单的另一个实例。
问题是,我只希望我的修改显示在我用于网站主导航的 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 渲染呢?
【问题讨论】:
-
菜单属性不适合您吗? drupal.org/project/menu_attributes
-
我见过那个模块,但它似乎并没有解决我想要做的事情:自定义菜单标记(不仅仅是菜单项属性),但将这些自定义设置为单个实例的特定菜单。不过,我在下面的回答是有效的。
标签: drupal drupal-7 drupal-theming