0

Hi my international friends!

I work in Drupal 7.38.

If the current page belongs to a specific content type, I want to activate a specific menu item. By to activate a specific menu item I mean that this menu item has the class active.

I try to do this with preprocess_page() function within template.php. It does not work :(.

Here is the code.

function MY_THEME_preprocess_page(&$vars) {
  if( !empty($vars['node']) ) {
    switch ( $vars['node']->type ) {
      case 'machine_name_my_content_type':
        menu_tree_set_path('machine_name_menu','path_menu_item');
        break;
      default:
        menu_tree_set_path('machine_name_menu','path_menu_item');
    }
  }
}

I have also tried a variation. Instead of putting:

menu_tree_set_path ('machine_name_menu' 'path_menu_item')

I put menu_set_active_item ('path_menu_item')

Nothing works!

Can you help me. Thanks in advance.

0

I would suggest looking at the Menu position module

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.