Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the tags associated to an article in Joomla

I need to get the TAGS associated with an article in Joomla 3.1.5

I have tried the following but they do not return a string:

echo $article->item->tags->itemTags;

and

$tags = $article->get("tags");

And just for the record I am loading the article info as such (getting the article title works perfectly)

$article = JTable::getInstance("content");
$article->load(JRequest::getInt("id"));
$pageTitle = $article->get("title");
$user =& JFactory::getUser();
like image 340
tim.baker Avatar asked Oct 06 '13 23:10

tim.baker


People also ask

How do I create content tags in Joomla?

There are two main ways to create content tags or Joomla article tags: 1. Ad-hoc Jommla article tags In each content where it is possible to apply the tags, you will see the contents as in the image here: In that space, you can add as many ad hoc tags as you want.

How to display the tags in the Joomla front end?

There are various ways to display the tags in the Joomla front end. 1. Tags in Content Items By default tags associated with any piece of content will automatically display on that content. You choose to show these content tags or not in the Article options, though by default these will show.

What is the Joomla API guide?

This is one of a series of API Guides, which aim to help you understand how to use the Joomla APIs through providing detailed explanations and sample code which you can easily install and run. This guide covers the APIs related to Joomla Tags functionality.

How do I view all items that have been tagged?

Once an item is tagged with a specific tag, browsing to the link for that tag will give a list of all items that have been tagged with that tag. Tags can be created in two ways.


2 Answers

If you want to load article tags in a module/plugin etc, and assuming $id is the id of the article, you can do

$tags = new JHelperTags;
$tags->getItemTags('com_content.article', $id);
var_dump($tags);
like image 85
Marko D Avatar answered Sep 30 '22 12:09

Marko D


If you look in components/com_content/views/article/tmpl/default.php, the tags are being displayed like so:

if ($this->params->get('show_tags', 1) && !empty($this->item->tags->itemTags)) {
    $this->item->tagLayout = new JLayoutFile('joomla.content.tags');
    echo $this->item->tagLayout->render($this->item->tags->itemTags);
}

So you can base it on this:

Hope it helps

like image 38
Lodder Avatar answered Sep 30 '22 14:09

Lodder