In Drupal 5, this function worked perfectly and simply returned a menu based on the unique menu id, regardless whether it was its own menu, or a sub menu of a larger menu.

In Drupal 6, this does not work at all. It simply returns the menu ID instead of the HTML formatted menu itself.

Comments

damien tournoud’s picture

Category: bug » support

The menu system changed a lot between Drupal 5 and Drupal 6, so it would help if you could give us more details about what you intend to do.

blue92877’s picture

Hi Damien,

In my Drupal 5 installations I used theme_menu_tree($mid) to extract the menu item with that id as well as the entire tree of children, (grandchildren, etc) below it.

In migrating to drupal 6 I created my menus and tried to use the same code for the same functionality. However, it simply returns the $mid I feed into the argument instead of the HTML rendered $tree as specified in the API.

This was useful because there are some parts of my menu I would like to show on specific pages in blocks designated for that page (sub menus). The original functionality of theme_menu_tree() allowed me to do that easily.

Now, however, the only function I can find is menu_navigation_links($menu_name).

This works for top level menus, and I have to feed it the menu name instead of the menu id. But it does not allow me to extract children from a main menu to create a sub menu

Hope that clarifies.

dharmatech’s picture

The Drupal Cookbook has a post on it:
http://drupal.org/node/685664

We tend to use Menu Block for a lot of our sites since it lets the administrator control the menu blocks.

If you still want to do it on your own for whatever reason, we've done this in the past in our template.php:

function menu_primary_children_links() {
  $pl = menu_tree_all_data('primary-links');
  $html = "";
  foreach ($pl as $k => $v) {
    if ($v['link']['hidden'] == 0) {
      $ul = '<div>'. $v['link']['title'] .'<ul>';
      foreach($v['below'] as $m) {
        if ($m['link']['hidden'] == 0) {
          $title = $m['link']['title'];
          $path = $m['link']['link_path'];
          $path = drupal_get_path_alias($path);
          if ($title != '') {
            $ul .= "<li>". print l($title, $path) ."</li>";
          }
        }
      }
      $ul .= '</ul></div>';
      $html .= $ul;
    }
  }

  return $html;
}

Then call it from theme_preprocess() in template.php:

$variables['menu_children'] = menu_primary_children_links(); 

and now you can use it in your page templates:

print $menu_children;

There's probably a bunch of different ways to accomplish the same thing depending on where/how you want to use the child menu.

blue92877’s picture

Hey, that's a great work around, thanks for the post!

Anonymous’s picture

Status: Active » Closed (fixed)

Looks like OP's question was answered.