Joomla 3 get the menu title
Asked Answered
R

4

2

I'm using multiple menus on one page. In multiple divs I'm showing a menu (menu1 to menu6). For templating purposes I would like to get the menu title of each menu to show on top. I'm not managing to get the title from the menu.

I found this is the way to get the menu items.

<?php
$menu = $app->getMenu();
$menu_items = $menu->getItems('menutype', 'menu1');
var_dump ($menu_items);
?>

Couldn't be so hard but can't find the right syntax. Who could help me?

Thanks in advance,

Wims

Rune answered 19/12, 2012 at 12:9 Comment(0)
P
8

Also you can use this one:

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

or if already $app = JFactory::getApplication(); exist

$menu = $app->getMenu();
$menuname = $menu->getActive()->title;
Palaeobotany answered 19/5, 2013 at 14:42 Comment(0)
P
4

The below code works for me in Joomla 3.0:

$app = JFactory::getApplication();

$menu = $app->getMenu();
$menuname = $menu->getActive()->title;
Pontine answered 17/10, 2013 at 11:46 Comment(0)
I
2

Use this:

/** Getting the Menu ID of Menu was clicked by user **/
$menu    =   &JSite::getMenu(); 
$id    =   $menu->getActive()->id;

/** Getting the Title of the Menu by using id. **/ 
$db    = JFactory::getDBO();
$query    = "SELECT title FROM kjs_menu WHERE id = $id";
$db->setQuery($query);
$rows    = $db->loadObjectList();
$itemrow = $rows[0];
$title   =   $itemrow->title;

echo "Menu you have clicked is : ".$title;
Interpol answered 19/12, 2012 at 12:40 Comment(1)
Thanks for your comment. This is not exactly what I ment. Iv'e solved the problem bij setting Joomla to show menu titles. In index.php I added style="xhtml": <jdoc:include type="modules" name="menu1" style="xhtml"/> In CSS the .moduletable class changed Thanks anyway. WimsRune
C
0

Since Joomla 3.8 you can use name spacing:

use Joomla\CMS\Factory;

echo Factory::getApplication()->getMenu()->getActive()->title;
Clyte answered 19/12, 2019 at 11:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.