简体   繁体   English

获得2个父级Joomla Title PHP

[英]Get 2 Parent level Joomla Title PHP

I know how to get the Current Page Title , also I know how to get the Menu Active Page Title but I need to actually get the 2 parent Active Menu via PHP. 我知道如何获得当前页面标题 ,我也知道如何获取菜单活动页面标题但我需要通过PHP实际获得2个父级活动菜单。

Active Menu Title 活动菜单标题

$app = JFactory::getApplication();
$menu = $app->getMenu();
$title = $menu->getActive()->title;

Menu Example 菜单示例

  • 1st Level - CARS 第一级 - CARS
    • 2nd Level - FERRARI 第二级 - 法拉利
      • 3rd Level - F50 3级 - F50

If I am at the 3 level menu F50 how can I get the CARS active menu title? 如果我在3级菜单F50 ,我如何获得CARS活动菜单标题?

Here you go: 干得好:

$app = JFactory::getApplication();
$menu = $app->getMenu();
$baseId = $menu->getActive($params)->tree[0]; //tree[1] for the second parent etc 

//query the database to find the title
$db = JFactory::getDBO();
$query = "SELECT title FROM #__menu WHERE id=".$baseId;
$db->setQuery( $query );
$topParentTitle = $db->loadResult();

A method, i used this: 一种方法,我用这个:

//import to faster development
jimport( 'joomla.application.categories' );

$options    = array();
$categories = JCategories::getInstance('Content', $options);
$category   = $categories->get($this->category->id);

$parent     = $category->getParent();

And here is the magic 这就是魔术

//here you get the grandparent category
$grandtemp = $categories->get($parent->id);
$grandparent = $grandtemp->getParent();

//print the values of parent of parent (1st level)
print_r($grandparent)

if you have any question you can comment 如果您有任何疑问,可以发表评论

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

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