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();
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.
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.
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.
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.
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);
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With