I am currently working on a module that finds out the parent menu item by url path then displays the current tree structure of that related menu by finding the top parent and most important only displaying that menu item and submenus from within that menu.
A simple solution would be having a foreach loop thru all items or an array with all items as keys.
path = '/system/menu/submenu';
parent = 'system';
output = parent + parent submenus.
All menu items in "Custom menu":
- System
- Menu wrapper
- SubMenu 1A
- SubMenu 2A
- SubMenu 3A
- Main
- SubMenu 1B
- SubMenu 2B
- SubChildMenu 3B
PHP code should return this:
- System
- Menu wrapper
- SubMenu 1A
- SubMenu 2A
- SubMenu 3A
My code (currently not working):
$menu = menu_tree('my-custom-menu');
return = theme('my_custom_menu', array('system' => $menu_tree));
Notice: This needs to be php code and php code only, all other modules does not support this only thru manual selection. The content is displayed thru a block.
"For the navigation, Drupal will call menu_tree_page_data via
menu_navigation_links which will only return a single level of links.
You can follow this function up to menu_main_menu and then
template_preprocess_page before it (which is how it ends up as a
variable in page.tpl.php)However, if you insert a menu as a block menu_tree_page_data is
called by menu_tree (which calls menu_tree_output immediately after
which does some additional work to the array for the final markup.)
After both have run you have your whole menu tree available as an
array which I then ran through some custom PHP code to loop through
the array and render it into an HTML list."
People have asked this before but i've tried their solutions and no success probable cause would be those questions is for drupal 6. I'm currently working with drupal 7.
Your help is very much appreciated, thanks...
Related questions:
http://stackoverflow.com/questions/5218861/restrict-menu-tree-to-first-l...
http://stackoverflow.com/questions/2716787/how-to-get-all-the-menu-items...
http://drupal.stackexchange.com/questions/28654/how-to-display-submenus-...
http://drupal.stackexchange.com/questions/30112/displaying-a-menus-child...
Comments
I'm not sure i know what
I'm not sure i know what you're doing here, but if you want to set active menu items by custom paths, menu_position will do it. It also supports custom rules for content types, roles, language and taxonomy. When you have your menu path rules set up, use menu_block to display the active menu items submenus/children.
The menu position module has a default setting of inserting the matching page title into the menu tree. In the modules settings you can change this behavior to mark the rule's parent menu item as being active instead.
Joakim Lundberg | Kollegorna