PHP
Joomla! 6
Joomla! 5
Joomla! 3 (Legacy)
Template Override
Basic
Generate a Friendly SEF URL for a Joomla Article
Builds a canonical SEF article URL honoring category, alias and language using RouteHelper and Route::_().
templates/seu_template/html/mod_articles/default.php
<?php
declare(strict_types=1);
use Joomla\CMS\Factory;
use Joomla\CMS\Router\Route;
use Joomla\Component\Content\Site\Helper\RouteHelper;
$app = Factory::getApplication();
$factory = $app->bootComponent('com_content')->getMVCFactory();
$article = $factory->createTable('Article', 'Administrator');
if ($article && $article->load((int) $item->articleid)) {
$slug = $article->id . ':' . $article->alias;
$link = Route::_(
RouteHelper::getArticleRoute($slug, (int) $article->catid, (string) $article->language)
);
}
Supports modern ID-less SEF routing and multilingual associations in Joomla 5 and 6.
templates/seu_template/html/mod_articles/default.php
<?php
$article = JTable::getInstance('content');
$article->load($item->articleid);
// Use slug somente se precisar de URL não amigável
// $slug = $item->articleid . ':' . $article->get('alias');
$link = JRoute::_(
ContentHelperRoute::getArticleRoute(
$item->articleid,
$article->get('catid'),
$article->get('language')
)
);
Legacy Joomla 3 snippet using JRoute and ContentHelperRoute.
Technical explanation and best practices
Whenever you need to output a canonical article link inside custom modules, plugins or template overrides, combine RouteHelper::getArticleRoute() with Route::_().
Providing the id:alias slug, catid and language guarantees accurate Itemid resolution on multilingual sites with modern ID-less routing.