0

I am new to Joomla. I have created a module that shows some articles with a link to those articles.

I fetched latest articals with :

<?php $list= ModArticlesLatestHelper::getList($params);
   foreach ($list as $item) :  ?>
     <a href="<?php echo $item->link; ?>" itemprop="url"></a>
<?php endforeach; ?>

i get a url that is in the form

`www.example.com/{articleID}-{article-name}`

Please tell me how can i get a URL in the following form.

www.example.com/{catagoryID}-{catagory-name}/{articleID}-{article-name}

  • Please post your code of how you formed $item->link. – Nagarjun Aug 30 '16 at 7:41
  • @Nagarjun I have edited my question, Please let me know if i need to provide any more details. thanks. – Prakhar Singh Aug 30 '16 at 9:36
0

Your article urls are managed using menu items. To get the correct menu structure, create one Category List or Category Blog menu item for each of the "Top Level" category. This way, your article urls will look like this:

/{categorymenualias}/{id}-{article-alias}

Or the articles in subcategories:

/{categorymenualias}/{catid}-{subcategory}/{id}-{article-alias}

Now in your module helper class, you can build your article urls using Content component helper.

$item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->id,  $item->catid ));

You may need to include the helper in your module.

require_once(JPATH_SITE.'/components/com_content/helpers/route.php');

Note: Your menu items can be under a Menus which you need not show on front-end using Menu module.

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.