Greetings,

The menu tree classes and ID defined in menu.inc menu_tree are applied to every menu which is bad because the main menu usually has some special css and effects that for example are not desirable in a custom footer or sidebar menu. Can menu.inc be updated to ONLY apply to main menu? Can you help me rewrite this snippet:

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

So that it applies to ONLY the main menu and not all other menus on the site? Many thanks! Kevin

Comments

shadcn’s picture

Yep. In template.php, you can add this code snippet inside the template_preprocess_page implementation.

function THEMENAME_preprocess_page(&$variables) {
  // Format and add main menu to theme.
  $variables['main_menu'] = menu_tree(variable_get('menu_main_links_source', 'main-menu'));
  $variables['main_menu']['#theme_wrappers'] = array('menu_tree__my_custom_nav');
}

then in menu.inc add this function:

/**
 * Implements theme_menu_tree__my_custom_nav().
 */
function THEMENAME_menu_tree__my_custom_nav(&$variables) {
  return '<ul class="my class">' . $variables['tree'] . '</ul>';
}

Flush cache.

pyxio’s picture

awesome. thanks for this! cheers Kevin

pyxio’s picture

Hi

I just had a chance to test this. Unfortunately... this does not work. all menus remain the same with the same markup as default drupal main menu. I know this has something to do with D7 problematic menu structures. I am wondering if better is to totally remove menu.inc from the theme but then i am not sure how to deal with menus. The fact is, other menus on site in sidebars and footer cannot inherit same styles as main menu. So this is a dilemma. Probably your approach is good but maybe the code has a bug somewhere. I definitely appreciate all of your help over the months and the great theme. Thanks Kevin

shadcn’s picture

Status: Active » Closed (works as designed)

Open Atrium is overwriting this by calling theme_menu_tree. See the implementation here: http://drupalcode.org/project/oa_radix.git/blob/refs/heads/7.x-2.x:/incl...

Closing this issue. Feel free to re-open.

Thanks