Question

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();
Was it helpful?

Solution 2

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

OTHER TIPS

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);

Rendering article tags in a module that displays Joomla articles, such as mod_articles_latest.

$itemtags = (new JHelperTags)->getItemTags('com_content.article', $item->id);
$taglayout = new JLayoutFile('joomla.content.tags');
$tags='';
if( !empty($itemtags) )
    $tags = '<div class="itemtags">'.str_replace(',','',$taglayout->render($itemtags)).'</div>';

Just to add to Marko D's answer, add this to format the tags like in an article/blog layout.

echo JLayoutHelper::render('joomla.content.tags', $tags->itemTags);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top