0

所以我一直在添加你在 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;
?>

如果不清楚,我可以尝试用不同的方式来解释。

4

1 回答 1

1

从某种意义上说,您的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的是什么,它可能会被删除,除非您在其他地方使用。

于 2013-11-14T10:15:14.167 回答