I have made a module in which I am fetching articles from a keyword present in alias.




    foreach($result as $row){

$url = "index.php?option=com_content&view=article&id=".$row['aid'].":".$row['aalias']."&catid=".$row['cid'].":".$row['calias']."&Itemid=???";

In building URL, how I can find item id?

I have tried to get item id from the following code found at Get full link from menu item field type

$itemid = $params->get('field_name'); 

$app = JFactory::getApplication();
$menu = $app->getMenu();
$link = $menu->getItem($itemid)->link;

But not sure what to pass in $params->get('field_name') in this case.

  • Which Joomla version are you using? I am a little bit confused about the colons ':' in your URL. An URL in Joomla 3.x would rather look like 'index.php?option=com_content&view=article&id=4&Itemid=555', for example.
    – fruppel
    Apr 14 '15 at 7:26
  • I am using joomla 3.4.1. URL is working fine if I give item id manually.
    – Agha
    Apr 14 '15 at 8:00

Use content component route helper. It will find Itemid for you.


include JPATH_SITE.'/components/com_content/helpers/route.php';

$articleLink = ContentHelperRoute::getArticleRoute($row['aid'], $row['cid']);

// SEF url
$articleLinkSEF = JRoute::_($articleLink);

  • Luckly enough I stumbled upon this! Where on earth is documented that ContentHelperRoute class? I tried searching but can't find it anywhere! Only found JHelperRoute but AFAICT it's not the same thing.
    – Gruber
    Apr 10 '16 at 0:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.