PHP
Joomla! 6
Joomla! 5
Joomla! 3 (Legacy)
Component
Basic
Get Category ID from an Article ID
Loads a com_content article by ID and retrieves its catid using the Joomla 5 and 6 MVCFactory or JTable in Joomla 3.
components/com_example/src/Helper/ArticleHelper.php
<?php
declare(strict_types=1);
use Joomla\CMS\Factory;
$app = Factory::getApplication();
$factory = $app->bootComponent('com_content')->getMVCFactory();
$article = $factory->createTable('Article', 'Administrator');
if ($article && $article->load((int) $item->articleid)) {
$catId = (int) $article->catid;
}
Uses native Joomla 5 and 6 component booting and MVCFactory without legacy JTable.
components/com_example/src/Helper/ArticleHelper.php
<?php
$article = JTable::getInstance('content');
$article->load($item->articleid);
$catId = $article->get('catid');
Original Joomla 3 syntax using JTable::getInstance('content').
Technical explanation and best practices
Useful whenever a module, plugin or layout override only receives an article ID and needs its catid to build routes, check category rules or display category metadata.
In Joomla 5 and 6, boot com_content and load the Article table through getMVCFactory() instead of legacy global classes.