Display a menu or part of it
Last modified: March 16, 2009 - 18:14
This is useful in cases when you want to display only part of the menu tree (e.g. sub-tree), or may be apply some pre-processing to the menu, or add some php or text before the menu itself.
First, you have to take note of the menu's mid, this can done from admin/menu, move over the "edit" link for your menu item, then in your browser's status bar there should be something like: http://example.com/admin/menu/item/edit/19, the latest argument is the mid, which is 19 in this example.
And here comes the php code:
<?php
$mid = 19;
print theme('menu_tree', $mid);
?>
It would be nice if there was
It would be nice if there was a 6.x equivalent of this PHP Snippet. For me it's been priceless!
If I find something then I will post it on this book page.
D6
Here's a snippet that words for primary menu... (at least on my site it works)
(adapted from here: http://drupal.org/node/256187)
<?php$tree = menu_tree_page_data('primary-links');
echo menu_tree_output($tree);
?>
Probably you can put any menu name in where you see 'primary-links'
But I don't know to print individual menu items.
Yes, but what about drilling
Yes, but what about drilling deeper than that? The example above shows getting down to the menu-id of a menu item to display all of it's children. That's the tricky part! :)
D6
Just to clarify, the snippet I posted May 11 is D6.
Drupal 6 version
I would love to see a Drupal 6 equivalent of the code example too!
Specifically, I would like to pass on just the menu ID have the entire tree generated from that point on.