[英]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).
在多个 div 中,我显示了一个菜单(menu1 到 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维姆斯
Also you can use this one:你也可以使用这个:
$menu = &Jsite::getMenu();
$menuname = $menu->getActive()->title;
or if already $app = JFactory::getApplication();
或者如果已经
$app = JFactory::getApplication();
exist存在
$menu = $app->getMenu();
$menuname = $menu->getActive()->title;
The below code works for me in Joomla 3.0:以下代码适用于 Joomla 3.0:
$app = JFactory::getApplication();
$menu = $app->getMenu();
$menuname = $menu->getActive()->title;
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;
Since Joomla 3.8 you can use name spacing:从 Joomla 3.8 开始,您可以使用名称间距:
use Joomla\CMS\Factory;
echo Factory::getApplication()->getMenu()->getActive()->title;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.