Breadcrumb and Menu Active for pages without menu items.

krolow - December 7, 2008 - 13:34

Hello, in the project where I'm working, it's possible has node without menu item, for these pages without menu item, is necessary when going to create a page set the node_reference, for us know, what page this page belongs to.

But the problems is we need, show the breadcrumb, and set in the menu the items actives:

    $node = menu_get_object();
  
    if (!has_item($node->nid)) {
        if (isset($node->field_reference[0]['nid'])) {
                $reference = $node->field_reference[0]['nid'];
        $cont = 0;
        //Verify if exist the item, and try catch the item until 10
        while (!has_item($reference) || $cont == 10) {
                        $cont++;
                        $new_node = node_load($reference);
                        $reference = $new_node->field_reference[0]['nid'];
                }
        }
        menu_set_active_item('node/'. $reference);
        $breadcrumb = build_breadcrumb($reference);
    }

    $breadcrumb[] = drupal_get_title();

    if (count($breadcrumb) > 1) {
        return implode(' » ', $breadcrumb);
    }

The breadcrumb I could set correct, but the item active, I can't do, because I don't know how it's possible set correct...

I try set the reference item active in the menu menu_set_active_item('node/'. $reference), but with this the anthers menu going to show the wrong Id of the node.

Please if possible give-me a solution.

tnks

 
 

Drupal is a registered trademark of Dries Buytaert.