因此,我一直在添加添加到Joomla!中文章的标签,效果很好。但是现在我想在Joomla中默认的文章列表布局中显示标签。
我找到了列表布局并对其进行了覆盖,并尝试将标签代码从单个文章布局添加到列表布局。下面是我尝试在列表布局中添加的代码。但布局中未显示任何标签。
<?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;
?>
如果不清楚,我可以尝试用另一种方式解释它。
您的php
作品在某种意义上说是建立了一组“标签”链接,但实际上并没有echo
出现在页面上。您需要在代码末尾或之后的某个位置(要显示标签的位置)添加此行。
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
的是什么,除非您在其他地方使用,否则它可能会被删除。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句