当菜单是单级列表时,我有一个预处理功能可以正常工作。但是,我希望它与吸盘鱼菜单一起工作。我想向顶级菜单项添加一个类,以便我可以设置它的样式。这是我用于单级菜单的代码:
function cti_flex_preprocess_page(&$vars, $hook) {
// Make a shortcut for the primary links variables
$primary_links = $vars['primary_links'];
// Loop thru the menu, adding a new class for CSS selectors
$i = 1;
foreach ($primary_links as $link => $attributes){
// Append the new class to existing classes for each menu item
$class = $attributes['attributes']['class'] . " item-$i";
// Add revised classes back to the primary links temp variable
$primary_links[$link]['attributes']['class'] = $class;
$link['title'] = '<span class="hide">' . check_plain($link['title']) . '</span>';
$i++;
} // end the foreach loop
// reset the variable to contain the new markup
$vars['primary_links'] = $primary_links;
}
我一直在尝试使用该menu_tree()
功能无济于事,例如:
function cti_flex_preprocess_page(&$vars, $hook) {
// Make a shortcut for the primary links variables
$primary_links = $vars['primary_links'];
// Loop thru the menu, adding a new class for CSS selectors
$i = 1;
foreach ($primary_links as $link => $attributes){
// Append the new class to existing classes for each menu item
$class = $attributes['attributes']['class'] . " item-$i";
// Add revised classes back to the primary links temp variable
$primary_links[$link]['attributes']['class'] = $class;
$link['title'] = '<span class="hide">' . check_plain($link['title']) . '</span>';
$i++;
} // end the foreach loop
// reset the variable to contain the new markup
$vars['primary_links_tree'] = menu_tree(variable_get('menu_primary_links_source', '$primary_links'));
}
任何想法将不胜感激。