[英]How to get menu active item
I have a project that im working on right now. 我有一个正在即时处理的项目。
I have developed it in Joomla, on the index page, I have a menu which shows the year. 我已经在Joomla的索引页面上开发了它,我有一个显示年份的菜单。
I need to know how to code a php variable to get the active item name of this menu so I can show ( echo
) it where I want. 我需要知道如何对php变量进行编码以获取此菜单的活动项目名称,以便可以在需要的地方显示( echo
)它。
See the attached screenshot. 请参阅随附的屏幕截图。
This should work 这应该工作
$currentMenuId = JSite::getMenu()->getActive()->id ;
Name: 名称:
JSite::getMenu()->getActive()->name;
or this 或这个
$menu = &JSite::getMenu();
$active = $menu->getActive();
$path = isset($active) ? array_reverse($active->tree) : null;
$thisPath = $path[(count($path)-1)];
echo $thisPath; //echo active menu id
The most simple method and sticking to Joomla coding standards is as follows: 遵循Joomla编码标准的最简单方法如下:
$menu = JFactory::getApplication()->getMenu();
$title = $menu->getActive()->title;
echo $title;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.