簡體   English   中英

如何獲取與Joomla中的文章相關聯的標簽

[英]How to get the tags associated to an article in Joomla

我需要獲得與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();

如果你想在模塊/插件等中加載文章標簽,並假設$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);
}

所以你可以基於這個:

希望能幫助到你

只是為了添加Marko D的答案,添加它來格式化文章/博客布局中的標簽。

echo JLayoutHelper::render('joomla.content.tags', $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>';

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM