I am trying to generate an URL for an article basead on Article ID.
After runing this query
SELECT a.sectionid,
CASE WHEN CHAR_LENGTH( a.alias )
THEN CONCAT_WS( ":", a.id, a.alias )
ELSE a.id
END AS slug,
CASE WHEN CHAR_LENGTH( cc.alias )
THEN CONCAT_WS( ":", cc.id, cc.alias )
ELSE cc.id
END AS catslug
FROM #__content AS a
INNER JOIN #__categories AS cc ON cc.id = a.catid
WHERE a.id = $articleID
I store my result in $data
and generate the link this way:
$link = JRoute::_(ContentHelperRoute::getArticleRoute($data[0]->slug, $data[0]->catslug, $data[0]->sectionid));
The problem is that the generated link its not correct when my article doesn't belong to any menu.
I noticed that when my article is not associated with any menu, the API gets the active menu id
and add to the generated link, the parameter "&Itemid=MyActiveMenuId"
(this happens in the route.php
file). But since the article doesn't exist in the active menu, the generated link will not work.
I know that if the API just ignores the "item menu id" instead of getting the "active menu id" it will work, but I can do this without change the Joomla code? Also, I want that the "item menu id" continue to be considered for the cases where an article actually belongs to a menu, so the generated URL will be SEF.
There is any way to solve this? Or every article must belong to a menu item?
My Joomla version is 2.5.13