【问题标题】:Article Tags shown in Article List-Layout文章列表布局中显示的文章标签
【发布时间】:2013-11-14 08:32:11
【问题描述】:

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

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

【问题讨论】:

    标签: joomla tags joomla3.0 article


    【解决方案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,它可能会被删除,除非您在其他地方使用。

    【讨论】:

    • 谢谢,您大部分都回答了我的问题!我还必须将这一行 $this->item->tags->itemTags as $i => $tag 更改为 $article->tags->itemTags as $i => $tag)。现在它在列表布局中显示标签!
    猜你喜欢
    • 2014-07-23
    • 1970-01-01
    • 2013-06-30
    • 1970-01-01
    • 2014-09-07
    • 2020-12-31
    • 1970-01-01
    • 2016-09-14
    • 1970-01-01
    相关资源
    最近更新 更多