简体   繁体   English

Joomla 3获得活动菜单项的父标题

[英]Joomla 3 get parent title of active menu item

I found on this thread : get active menu item title how to get the title of active menu item : 我在这个帖子上找到了: 获取活动菜单项标题如何获取活动菜单项的标题

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

but how can I get his parent menu item title? 但我怎样才能得到他的父菜单项目标题?

This should work 这应该工作

$menu = JFactory::getApplication()->getMenu();
$parent = $menu->getItem( $menu->getActive()->parent_id );
$parentname = $parent->title;
$parentlink = JRoute::_( $parent->link . '&Itemid=' . $parent->id );

It's been while since I worked with Joomla, nevertheless give this a try: 我和Joomla合作已经有一段时间了,不过尝试一下:

$menu     = JSite::getMenu();
$active   = $menu->getActive();
$parent   = $menu->getItem($active->parent);

Then you can use $parent as any other menu item: 然后你可以使用$parent作为任何其他菜单项:

echo $parent->title;

What I just used was this: 我刚用的是这个:

$menu = &JSite::getMenu();
$active = $menu->getActive();
$menuname = $active->title;
$parentId = $active->tree[0];
$parentName = $menu->getItem($parentId)->title;
$parentlink = $menu->getItem($parentId)->alias;
echo "<h1><a href=\"$parentlink\">".$parentName."</a></h1>";

Found most of this in the Joomla forum and added the alias part, which I guessed ... This works with SEF URLS and URL rewriting on. 在Joomla论坛中找到了大部分内容,并添加了别名部分,我猜到了......这适用于SEF URLS和URL重写。 Anyway, the title line: 无论如何,标题行:

&JSite::getMenu()->getItem(&JSite::getMenu()->getActive()->tree[0])->title;

... which should be the same as what AlexP listed, I didn't check if it's exactly the same. ......应该和AlexP列出的相同,我没有检查它是否完全一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM