PHP Joomla! 6 Joomla! 5 Joomla! 3 (Legacy) Template Override Basic

Get Current Category and Parent Category ID

Fetches a CategoryNode object and reads its parent category using the com_content category service.

Updated on 24 November 2026 26 copies 120 views
templates/seu_template/html/com_content/category/blog.php
<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$categories = Factory::getApplication()->bootComponent('com_content')->getCategory();
$category   = $categories ? $categories->get((int) $catid) : null;

if ($category) {
    $parentId = (int) $category->parent_id;
    $parent   = $category->getParent();
    echo $parentId;
}
Uses the cached Joomla 5 and 6 CategoryService tree.
templates/seu_template/html/com_content/category/blog.php
<?php
$category = JTable::getInstance('category');
$category->load($catid);
echo $category->parent_id;
Legacy Joomla 3 approach using JTable::getInstance('category').

Technical explanation and best practices

In nested category structures such as blogs, portfolios or knowledge bases, you often need the parent category ID or title for navigation context or CSS styling.

In Joomla 5 and 6, bootComponent('com_content')->getCategory() leverages the cached category tree without redundant database queries.

Direct Engineering

Have a Joomla project or technical challenge in mind?

From architectural diagnosis to production deployment, directly with the engineer.