[英]Get 2 Parent level Joomla Title PHP
我知道如何获得当前页面标题 ,我也知道如何获取菜单活动页面标题但我需要通过PHP实际获得2个父级活动菜单。
$app = JFactory::getApplication();
$menu = $app->getMenu();
$title = $menu->getActive()->title;
如果我在3级菜单F50 ,我如何获得CARS活动菜单标题?
干得好:
$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();
一种方法,我用这个:
//import to faster development
jimport( 'joomla.application.categories' );
$options = array();
$categories = JCategories::getInstance('Content', $options);
$category = $categories->get($this->category->id);
$parent = $category->getParent();
这就是魔术
//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)
如果您有任何疑问,可以发表评论
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.