Joomla 3获得菜单标题

问题描述 投票:2回答:4

我在一页上使用多个菜单。在多个div中,我显示一个菜单(菜单1至菜单6)。出于模板目的,我希望将每个菜单的菜单标题显示在顶部。我没有从菜单中获取标题。

我发现这是获取菜单项的方法。

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

没那么难,但是找不到正确的语法。谁能帮助我?

谢谢,

Wims

php menu title joomla3.0
4个回答
8
投票

也可以使用这个:

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

或者如果已经存在$app = JFactory::getApplication();

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

4
投票

以下代码在Joomla 3.0中对我有效:

$app = JFactory::getApplication();

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

2
投票

使用此:

/** 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;

0
投票

自Joomla 3.8起,您可以使用名称间距:

use Joomla\CMS\Factory;

echo Factory::getApplication()->getMenu()->getActive()->title;
© www.soinside.com 2019 - 2024. All rights reserved.