tags:

views:

97

answers:

4

So I've got a content type of "News" and then a View which shows a list of News nodes as a menu item.

Is there any way to highlight the News View in the menu tree when you're viewing a News node?

I'm sort of aware of why this doesn't work, and why doing this might be hacky, but there's got to be a way to have a "default" menu item or something that a node can show up under.

A: 

Assuming the answer to my above comment is "yes," this is something you can accomplish through the template.php file in your theme folder

The final solution will depend on your settings, but generally most of the action will happen inside phptemplate_preprocess_page

// Simplified, and untested in this form
    function phptemplate_preprocess_page(&$vars) {                        
      if (isset($vars['node'])) { // if we're looking at a node
        $body_classes[] = (($vars['node']->type == 'News') || (arg(0) == 'News')) ? 'news_page' : '';             // Page is news page
      }
      else if (arg(0) == 'taxonomy') {
        // ... Special handling for news taxonomy pages, if you want
      } else {
        $body_classes[] = "page-type-" . arg(0);
      }
      $body_classes = array_filter($body_classes); // Out! Out! Damn empty elements!
      $vars['body_classes'] = implode(' ', $body_classes);  
    }

This will give the you the body.news_page style class to work with, and you can combine that with the style of your news menu block to make it appear how you like.

anschauung
+1  A: 

Actually, I found a module that does basically what the template.php answer above does, by allowing you to assign a default menu item by content type.

It's called Menu Trails: http://drupal.org/project/menutrails

Karl
A: 

if Menutrails doesn't work (for me it didn't) you can do it yourself by something like:

$somenode = menu_get_item('node/5');

menu_set_item($somenode);

Niels
A: 

I have found you have more control if you do something like this in hook_nodeapi().

// this code worked for me
$somenode = menu_get_item();
$somenode['href'] = 'node/5';
menu_set_item(NULL, $somenode);

You may need to set the weight of your custom module to be heavier than core modules: at least 1

Matt