Reputation: 21
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
Upvotes: 2
Views: 14627
Reputation: 444
Since Joomla 3.8 you can use name spacing:
use Joomla\CMS\Factory;
echo Factory::getApplication()->getMenu()->getActive()->title;
Upvotes: 0
Reputation: 51
The below code works for me in Joomla 3.0:
$app = JFactory::getApplication();
$menu = $app->getMenu();
$menuname = $menu->getActive()->title;
Upvotes: 4
Reputation: 487
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;
Upvotes: 8
Reputation: 2047
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;
Upvotes: 2