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?
This should work
$menu = JFactory::getApplication()->getMenu();
$parent = $menu->getItem( $menu->getActive()->parent_id );
$parentname = $parent->title;
$parentlink = JRoute::_( $parent->link . '&Itemid=' . $parent->id );
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;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With