Ok, so in D5, I believe you can print menu_tree with the pid of the menu portion you want to print, but D6 takes menu_name as a parameter, and only the root menus seem to have names. Anyone know what to do about this?

What I'm aiming for... I have this menu:

item 1
item a
item b
item c
item 2
item d
item e
item f

On one part of the page I just want to print item 2 and the elements beneath it, thus:

item 2
item d
item e
item f

I'm stumped.

Comments

phl3tch’s picture

Oops, my formatting didn't really come out on those menu examples. They should be understandable anyway -- the alphabetically indexed items should be indented.

klaasvanschelven’s picture

Try the local menu module:

http://drupal.org/project/local_menu

phl3tch’s picture

I wound up not using it, as it didn't do exactly what I wanted, but examining the source code made me realize what the solution was. Namely, array_slice. I think sometimes I'm so certain there's a Drupal way to do things that I forget I can write PHP. So anyway, for the benefit of others, my dreadfully simple solution (considering I've been fiddling with this for 2 days) is this:

$tree = array_slice( menu_tree_page_data('primary-links'), 2, 1 );
echo menu_tree_output($tree);
Fenwick’s picture

Does anyone know how to do this, but for only part of the menu (with children)? I have a menu named "menu-mymenu" that looks like this:

* Item 1
  *Item 1-a
    * Item 1-a-i
    * Item 1-a-ii
    * Item 1-a-iii
  *Item 1-b
    * Item 1-b-i
    * Item 1-b-ii
    * Item 1-b-iii
* Item 2
  *Item 2-a
    * Item 2-a-i
    * Item 2-a-ii
    * Item 2-a-iii

and I want to pull and display a menu (Item 1-b plus all its children) that looks like this:

*Item 1-b
  * Item 1-b-i
  * Item 1-b-ii
  * Item 1-b-iii

I can get the whole menu using

$tree = menu_tree_all_data('menu-mymenu');

But my menu is very large, and the descriptions of each taxonomy term (loaded with $tree) are large, resulting in a huge performance hit if I just pull the whole tree. I will do that if I have to, but would like to avoid it.

I see two possible approaches. One is to use php array_slice($tree) as outlined above to snip out the portion of the menu I need -- but the menu array is so complicated I am not quite sure how to do this and I appreciate any help or pointers.

The second approach is to take the performance hit and pull the submenu based on its plid, but I'm not sure how to do this. I've read the documentation on menu_tree , menu_tree_data , and menu_tree_all_data but still can't figure out how to pull just the submenu I want. I'm beginning to suspect this is not possible.

http://api.drupal.org/api/function/menu_tree/6
http://api.drupal.org/api/function/menu_tree_data/6
http://api.drupal.org/api/function/menu_tree_all_data/6

Help?

Fenwick’s picture

Clarification -- The performance hit is for option 1 (array_slice) not option 2 (pull just the sub-menu). I've been staring at code for nine hours straight and can't think straight at the moment.

blue92877’s picture

Fenwick,

Did you find a solution to this issue?

In Drupal 5, the function theme_menu_tree() 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.

Anyone figured out the equivalent of this function for drupal 6 that doesn't involve very complicated programming to accomplish?

tamanna-freelancer’s picture

try creating another menu which just has the submenu and use it.

drhus’s picture

it used to be b4 D5
something like

$mid = 557;
print theme('menu_tree', $mid);

(where mid can be id of submenu..)
done

but now i don't know how to do it ....