1

How can I get the parent items of a menu item for a view? I added a Global: null argument in the view and I need to get the parent items of this view. The view is set to belong to a menu in admin/build/menu-customize/primary-links.

I tried these in the argument to examine the parent items: $menuParent = menu_get_active_trail(); dsm($menuParent);

However, it's not resulting in the output I hoped. I tried to look for a right function in http://api.drupal.org/api/drupal/includes--menu.inc/group/menu/6 but I get confused with all these functions: menu_tree, menu_tree_data, menu_get_ancestors etc.

I am using Drupal 6.

2

There is not an easy way to get the parent of a specific menu item. The problem is that a path can be in many menus so you need to not only know the path of the item whose parant you want to find, but also which menu to look for them.

The menu_links table hold the info and with a few queries you could find info about the parent. If you actually want to change anything in the menu being printed, that's a completely different story, and can be quite tricky in Drupal 6.

To get menu item you could do something like this:

$path = 'foo';
$menu = 'bar'
$mlid = db_result(db_query("SELECT plid FROM {menu_links}
          WHERE link_path = '%s'
          AND menu_name = '%s'";, array($path, $menu)));

$menu_item = menu_get_item($mlid);
// $menu_item is now the parent menu_item of the menu in bar with path foo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.