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.
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.
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:
$menu = JFactory::getApplication()->getMenu();
$title = $menu->getActive()->title;
echo $title;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.