So, I'm using the primary menu system and outputting my primary menu in one place and then the secondary somewhere else. What I want to do is have a block which outputs me the parent menu item regardless if I am on the parent item, one level in or two levels in .. Essentially 2 levels is as deep as I go.

I would love if someone could direct me as to how to do this.

I just need the parent menu item's title .. That's it. That will be output in my block.

Thanks so much for any help.

Cheers,

Adam

Comments

nimzie’s picture

I guess, to be more specific, to get the parent menu item of the currently selected menu item in Primary Links menu.
I've looked around at the functionality around breadcrumbs, menu and a few other places and with my limited knowledge, am turning up nothing so far.

I would assume this should be simple. Some way to get a menu id from the node id then see if it has a parent and go up the chain. I don't speak Drupalese well, but I know what I'm looking for...

Thanks for any assistance.

Cheers,

Adam

nimzie’s picture

Can anyone help with this functionality? I'm super stumped and this is holding me up bigtime.

Even a clue? I've tried a couple of things, but just haven't grasped "the drupal way" ... yet.

Cheers,

Adam

ESBertrand’s picture

Adam, did you ever find a way to do this? I'm also struggling with this, and I've not heard from anyone yet either. It's been almost a year and a half for you -- hopefully it won't be that long for me! If you did find a way to do this, please let me know. Thanks!

Erik

Romisha’s picture

Hey!! I am too looking for this since long. But no success :(

Many thanks in advance!!

ESBertrand’s picture

I worked with this tonight and found a way that seems to work, for 6.x or newer anyway:

   $menuTrail = menu_get_active_trail("node/$node->nid"); ?>
   if ($menuTrail[1]) {
      print $menuTrail[1]["title"];
   }

I'm using this to print the title of the top-level parent of the current page. So far this prints the right title whether you're on the top-level parent itself, or any of its children. I haven't yet tried this when you're at tertiary or deeper levels, but I think it should work since $menuTrail[1] will always be the top-level primary link parent.

In case it matters, I'm using the setup where primary links are themselves, and secondary links are derived from primary link children. I'm a Drupal newbie, and quite new at PHP, too, so I'm sloughing along slowly but surely.

If anyone more learned has a better way to do this, please post for my and others benefit! Thanks.

Erik

ak’s picture

Hi, I'm trying the same. I pasted your code in my page.tpl.php. But the only thing I get is the title of the current node or menu entry but not it's parent.

I'd like to display the title of the parent menu item of a node in the nodes title based on the primary links? I'm researching for ages now …

paddyguest’s picture

If Menu Breadcrumb is not enabled, then this code gives you the title of the current node. If it is enabled then it gives you the title of the page at the top of the tree.

Hope this helps to save someone else the hours of searching that I have spent on it!