2

I searched google and read many articles but no luck, is there a way to get the link of a category for joomla 3.3.6 item/article.

More details: I'm building a custom theme on Joomla 3.3.6 I have managed to display articles in the main page as thumbnails and inside these thumbnails image, description ,read more link and category, the read more link goes directly to the article. One last thing left for me when user clicks category name it will forward to category page.

In code i can get article id, article title, article category, and article link. I don't know how to make a link of these, like: http://www.host/category_name/article_id-article_name

Anyone knows how to make it,

Thanx,

2
  • you want to display category link in thumbnail (that article belongs to)?? Your sample link seems to represent article link under a category
    – Nick
    Commented Mar 14, 2015 at 16:10
  • Are you looking to get this from inside the template?
    – FFrewin
    Commented Jun 11, 2015 at 19:08

2 Answers 2

2

Use ContentHelperRoute to get article category url. It can be one like this this article view:

JRoute::_(ContentHelperRoute::getCategoryRoute($this->item->catslug))

If you need this out of com_content component you will have to add ContentHelperRoute declaration too:

require_once JPATH_SITE.'/components/com_content/helpers/route.php'

And $this->item->catslug will change to something like this $item->catslug. It depends on in what variable do you store article info. catslug contains combined category ID and category alias in this way: ID:ALIAS. System use this way for all category url's so it would be better to follow this practice to assure links stay consistent.

Links

1

Do something like this:

<?php 
$catID = JRequest::getVar('catid');
echo "<a href='index.php?option=com_content&view=category&layout=blog&id=".$catID."'>Link to blog view of category</a><br />";
?>

This works, of course, only if you have article shown in "component" position at the moment. Link is blog view of current item's category. Not so perfect, but does what you want. Complete solution would be to see if you already have defined that blog view within menu and then adding $Itemid at the end of url. Then, for more complete solution use something like this:

$catID = JRequest::getVar('catid');
echo '<a href="'.JRoute::_(ContentHelperRoute::getCategoryRoute($catID)).'">Link to menu item of category if exists</a>';

Texts within <a> tags can be replaced by category title for example...

1
  • JRequest is deprecated in Joomla 3.x
    – Lodder
    Commented Sep 29, 2015 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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