2013-08-01 88 views
2

我有一個類別ID,並不想顯示所有子類別。我應該在Joomla中做這個嗎?Joomla獲取自定義父類別的子類別

我已經試過以下

$catID = JRequest::getVar('id'); 
$categories = JCategories::getInstance('Content'); 
$cat = $categories->get($catID); 
$children = JCategoryNode::getChildren($cat); 
printObject($children); 

但它不工作。

+0

什麼是$孩子?你不要在顯示的代碼中的任何地方定義它。 –

+0

@PatrickEvans對不起,我忘了一行$ children = JCategoryNode :: getChildren($ cat); (編輯代碼) –

回答

9

getChildren不是一個靜態函數,你可以將它從get獲得的類別對象稱爲JCategoryNode。

$catID = JRequest::getVar('id'); 
$categories = JCategories::getInstance('Content'); 
$cat = $categories->get($catID); 
$children = $cat->getChildren(); 
print_r($children); 

JCategorNode api

+0

非常感謝。那麼沒有ai可以在$ categories var上使用任何JCategoryNode方法?像getNumItems,getSibling等,對吧? –

+0

不,$ categories是JCategories的一個實例,您可以在$ cat上使用JCategoryNode方法,也可以在$ children中使用任何$ children,因爲它們也是JCategoryNode。 –

相關問題