我需要获取与Joomla 3.1.5中的文章关联的标签
我已经尝试了以下内容,但它们没有返回字符串:
echo $article->item->tags->itemTags;
和
$tags = $article->get("tags");
只是为了记录,我正在加载文章信息(获取文章标题效果很好)
$article = JTable::getInstance("content");
$article->load(JRequest::getInt("id"));
$pageTitle = $article->get("title");
$user =& JFactory::getUser();
如果你想在模块/插件等中加载文章标签,并假设$id
是文章的id,你可以这样做
$tags = new JHelperTags;
$tags->getItemTags('com_content.article', $id);
var_dump($tags);
如果你看components/com_content/views/article/tmpl/default.php
,标签显示如下:
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);
}
所以你可以基于这个:
希望对你有帮助
在显示 Joomla 文章(如 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>';
只是为了添加到 Marko D 的答案中,添加它以格式化标签,就像在文章/博客布局中一样。
echo JLayoutHelper::render('joomla.content.tags', $tags->itemTags);