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.
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.