问题
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();
回答1:
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
回答2:
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);
回答3:
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>';
回答4:
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);
来源:https://stackoverflow.com/questions/19215132/how-to-get-the-tags-associated-to-an-article-in-joomla