如何获取与Joomla中的文章相关联的标签

时间:2013-10-06 23:25:23

标签: php joomla tags joomla3.1

我需要获得与Joomla 3.1.5中的文章相关联的TAGS

我尝试了以下内容,但它们没有返回字符串:

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

4 个答案:

答案 0 :(得分:13)

如果您想在模块/插件等中加载文章标签,并假设$id是文章的ID,您可以

$tags = new JHelperTags;
$tags->getItemTags('com_content.article', $id);
var_dump($tags);

答案 1 :(得分:8)

如果查看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);
}

所以你可以基于此:

希望有所帮助

答案 2 :(得分:2)

只是添加到Marko D的答案中,添加它以格式化文章/博客布局中的标记。

echo JLayoutHelper::render('joomla.content.tags', $tags->itemTags);

答案 3 :(得分:2)

在显示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>';
相关问题