Search code examples
joomlajoomla2.5joomla3.1

Joomla Get subcategories of custom parent category


I have a category ID and wan't to display all the subcategories. Show should I do that in Joomla?

I've tried the following

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

But it doesn't work.


Solution

  • getChildren is not a static function, you call it off the category object that you get from get, which should be of type JCategoryNode.

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

    JCategorNode api