I work with Drupal 7. I have a view news with an overview of nodes with content type news. The view news has a menu item in the main menu.

When I go to the view news via the main menu the menu link news is highlighted. I would like to highlight main menu link news also when I visit a news item page.
But i can't find a solution for drupal 7.

I need something that sets menu item news active when I view a node with content type news.

Module menu trails has no Drupal 7 version, Context module doesn't work because I have no context entry in menu structure. Are there other solutions? Maybe via code or other modules.

Comments

AngeloFallein’s picture

Set parent menu item news to "view" news.
Style the .active-trail class as active in the main menu.

hroutil’s picture

Hi, it seems I have exactly the same problem but unfortunately I'm not sure what you mean with the "Set parent menu item news to "view" news."

Can you explain it little bit for me? Thank you!

jbfelix’s picture

- Edit your view called news
- Click on "+" near arguments and choose "Node: Title" keeping all default values
- Save your view
- Using pathauto module, define the pattern for all "news" content type to news/[node:title]
- edit all your "news" content types and check "automatic URL" to update their url.

Thats all

fugudesign’s picture

Hi, I have the same problem.
I don't understand "Set parent menu item news to "view" news." and the "Working solution" don't work for me.
Additionaly, should I do something with the menus?

Thanks

hroutil’s picture

Thanks for your reply!

I resolved this problem using "themename_menu_link" function in my template.php file.
I can post a snippet if someone interested.

hubertusanton’s picture

could you post the snippet?

akozoriz’s picture

My snippet for main-menu and node type 'article'

function themename_menu_link(array $variables) {
  $path_parts = array();
  $element  = $variables['element'];
  $sub_menu = '';
  $menuName = $variables['element']["#original_link"]["menu_name"];
  //Check menu name
  if($menuName == 'main-menu')
  {
    $path_parts = explode('/',$element['#href']);
    if($path_parts[0]=='node' && is_numeric($path_parts[1]))
    {
      $menu_load_node = node_load($path_parts[1]);
      //Check node type (In our case 'article')
      if($menu_load_node->type == 'article')
      {
        $element['#attributes']['class'][] = 'highlight';
      }
    }
  }
  if ($element['#below']) {
    $sub_menu = drupal_render($element['#below']);
  }
  $output = l($element['#title'], $element['#href'], $element['#localized_options']);
  return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}
meerkat’s picture

I was really hoping that "working solution" would do just that because this issue is preventing me from migrating from Drupal 6 to Drupal 7, but it doesn't work - or at least I haven't been able to make it work (no "active" or "active-trail" classes when displaying the menu-less node).

In the past I've used Node Breadcrumb to maintain navigational context but this hasn't been updated for D7 yet - and it never made it beyond beta for D6 so I don't expect a D7 version any time soon.

Any other suggestions?

meerkat’s picture

For anyone else struggling with this in D7 try the Menu Position module. Early days but it seems to meet the need perfectly.

botris’s picture

The context module has an option to set the active item. So you can just set the Condition to a View or Node type (or both) and the Reaction has a menu option where you can specify the menu item to be active.

felubra’s picture

Very thanks @Boriss!

jaydarnell’s picture

Unfortunately this only updates the individual item selected and does nothing to create an active trail for parent items. I had high hopes for using context in this situation but this was pretty disappointing.

Jay Darnell - CivicActions
Web Designer / Developer / Illustrator

gettysburger’s picture

I am stuck on the same problem. Context neatly sets the class of my to active, but not the

  • . Any thoughts now, two years later? Thanks.
  • marco van bemmel’s picture

    Hi Gettysburger,
    Take a look at Menu Position. Maybe this module can help you?