文章列表布局中显示的文章标签 [英] Article Tags shown in Article List-Layout
问题描述
所以我一直在添加您在 Joomla! 中添加到文章的标签,效果很好.但现在我想在 Joomla 中默认的文章列表布局中显示标签.
So I've been adding tags you add to articles in Joomla!, which works fine. But now I want to show the tags in the article list layout that is default in Joomla.
我找到并覆盖了列表布局,并尝试将单个文章布局中的标签代码添加到列表布局.下面是我试图在列表布局中添加的代码.但是布局中没有显示任何标签..
I found and made an override for the list-layout and tried to add the tags code from a single article layout to the list-layout. Underneath is the code I tried to add in the list-layout. But none of the tags are shown in the layout..
<?php
// set tags
$tags = '';
if (!empty($this->item->tags->itemTags)) {
JLoader::register('TagsHelperRoute', JPATH_BASE . '/components/com_tags/helpers/route.php');
foreach ($this->item->tags->itemTags as $i => $tag) {
if (in_array($tag->access, JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id')))) {
if($i > 0) $tags .= ', ';
$tags .= '<a href="'.JRoute::_(TagsHelperRoute::getTagRoute($tag->tag_id . ':' . $tag->alias)).'">'.$this->escape($tag->title).'</a>';
}
}
}
$args['tags'] = $tags;
?>
如果这不是很清楚,我可以尝试换一种方式来解释.
If this isn't clear, I can try to explain it a different way.
推荐答案
你的 php
的工作原理是它构建了一组标签"链接,但它实际上并没有 echo
把它放到页面上.您需要在代码的末尾或之后的某处添加此行,以便在其中显示标签.
Your php
works in the sense that it builds a set of "tag" links but it doesn't actually echo
it out to the page. You need to add this line either at the end of your code or somewhere after, where you want to display the tags.
echo $tags;
例如
<?php
// set tags
$tags = '';
if (!empty($this->item->tags->itemTags)) {
JLoader::register('TagsHelperRoute', JPATH_BASE . '/components/com_tags/helpers/route.php');
foreach ($this->item->tags->itemTags as $i => $tag) {
if (in_array($tag->access, JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id')))) {
if($i > 0) $tags .= ', ';
$tags .= '<a href="'.JRoute::_(TagsHelperRoute::getTagRoute($tag- >tag_id . ':' . $tag->alias)).'">'.$this->escape($tag->title).'</a>';
}
}
}
$args['tags'] = $tags;
echo $tags;
?>
我不确定您将 $args
用于什么目的,它可能会被删除,除非您在其他地方使用.
I'm not sure what you're using $args
for either, it could probably be removed, unless you're using somewhere else.
这篇关于文章列表布局中显示的文章标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!