[英]Get name of top-level menu - Joomla 3
I have some menu-items published on footer of my site. 我在网站的页脚上发布了一些菜单项。
-FAQ
-Contact Us
These are actually menu-items and their main menu name is Information
这些实际上是菜单项,它们的主菜单名称是“ Information
I want to show their main-menu name as well like so: 我也想显示它们的主菜单名称:
Information
-FAQ
-Contact Us
I have this code 我有这个代码
$menu = JFactory::getApplication()->getMenu();
$parent_title = $menu->getItem(2)->title;
The main menu named Information
has id 2
but it does not show anything :( 名为Information
的主菜单具有ID 2
,但未显示任何内容:(
So how do I get that menu name? 那么如何获得该菜单名称?
Lets try this way: 让我们尝试这种方式:
$menu = JFactory::getApplication()->getMenu();
$active = $menu->getActive();
$parent = $menu->getItem($active->parent_id);
var_dump(parent);
and tell us what you get : ) 并告诉我们您得到了什么:)
if this don't work for you, change line with parent to: 如果这对您不起作用,请将与parent的行更改为:
$parent = $menu->getItems('id', $active->parent_id);
regards 问候
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.