By flamingvan on
If I have the mid of a menu item, how can I determine what level the menu item lives at in the menu hierarchy? Or can I simply determing if the menu item has a parent or is a top level item?
Thanks!
If I have the mid of a menu item, how can I determine what level the menu item lives at in the menu hierarchy? Or can I simply determing if the menu item has a parent or is a top level item?
Thanks!
Comments
Is this impossible?
Can't be. There must be an easy way.
The solution
$parent = menu_get_item($vars['mid']);
$vars['parent'] = $parent['pid'];
$hasParent = menu_get_menu();
$hasParent = $hasParent['items'][$parent]['pid'] == 0 ? 0 : 1;
I hope the helps somebody!
Explanation?
Hey flamingvan, can you provide a little explanation of what your code is doing? When I put this in a node and print $parent and $hasParent, I get an error:
warning: Illegal offset type in /Applications/MAMP/htdocs/drupal/includes/common.inc(1352) : eval()'d code on line 9.. I'm trying to print in each node a link to its parent node, if it has one. Thanks for any help.I'm trying to use this code
I'm trying to use this code as well and am unable to get it to work whether I print the vars out or not.
I'd like to use this with D 5.x and output the top level parent menu item.
Thanks for any help.
Cheers,
Adam
Simplest
Simplest way:
This will work in your template.php file.
This only works if you're
This only works if you're looking for the parent item of a menu link that exists in the current page active trail, no? If I have a mlid that I want to look up the parent for, this won't work. Is that correct?
Extremely useful
Extremely useful snippet of code, thanks