我有一個預處理函數,當菜單是單層列表時,可以正常工作。不過,我希望它能工作w/suckerfish菜單。我想添加一個類到頂層菜單項,以便我可以設置它的樣式。這是我用於單級菜單代碼:Drupal主題預處理函數 - 主鏈接和suckerfish菜單
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'));
}
任何想法,將不勝感激。