Joomla 3 get the menu title

删除回忆录丶 提交于 2019-12-07 23:14:22

问题


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


回答1:


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;



回答2:


The below code works for me in Joomla 3.0:

$app = JFactory::getApplication();

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



回答3:


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;


来源:https://stackoverflow.com/questions/13952199/joomla-3-get-the-menu-title

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!