user1915721
user1915721

Reputation: 21

Joomla 3 get the menu title

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

Answers (4)

pe7er
pe7er

Reputation: 444

Since Joomla 3.8 you can use name spacing:

use Joomla\CMS\Factory;

echo Factory::getApplication()->getMenu()->getActive()->title;

Upvotes: 0

Lakshmi Bade
Lakshmi Bade

Reputation: 51

The below code works for me in Joomla 3.0:

$app = JFactory::getApplication();

$menu = $app->getMenu();
$menuname = $menu->getActive()->title;

Upvotes: 4

Lahmizzar
Lahmizzar

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

harikrishnan.n0077
harikrishnan.n0077

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

Related Questions