[英]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.