Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Joomla 3 get parent title of active menu item

I found on this thread : get active menu item title how to get the title of active menu item :

$menu = &Jsite::getMenu();
$menuname = $menu->getActive()->title;

but how can I get his parent menu item title?

like image 547
web-tiki Avatar asked Aug 28 '13 21:08

web-tiki


3 Answers

This should work

$menu = JFactory::getApplication()->getMenu();
$parent = $menu->getItem( $menu->getActive()->parent_id );
$parentname = $parent->title;
$parentlink = JRoute::_( $parent->link . '&Itemid=' . $parent->id );
like image 169
Kaerber Avatar answered Oct 06 '22 08:10

Kaerber


It's been while since I worked with Joomla, nevertheless give this a try:

$menu     = JSite::getMenu();
$active   = $menu->getActive();
$parent   = $menu->getItem($active->parent);

Then you can use $parent as any other menu item:

echo $parent->title;
like image 24
AlexP Avatar answered Oct 06 '22 07:10

AlexP


What I just used was this:

$menu = &JSite::getMenu();
$active = $menu->getActive();
$menuname = $active->title;
$parentId = $active->tree[0];
$parentName = $menu->getItem($parentId)->title;
$parentlink = $menu->getItem($parentId)->alias;
echo "<h1><a href=\"$parentlink\">".$parentName."</a></h1>";

Found most of this in the Joomla forum and added the alias part, which I guessed ... This works with SEF URLS and URL rewriting on. Anyway, the title line:

&JSite::getMenu()->getItem(&JSite::getMenu()->getActive()->tree[0])->title;

... which should be the same as what AlexP listed, I didn't check if it's exactly the same.

like image 22
Ralf Avatar answered Oct 06 '22 08:10

Ralf