在文章列表布局中显示的文章标签 [英] Article Tags shown in Article List-Layout

查看:110
本文介绍了在文章列表布局中显示的文章标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我一直在添加要添加到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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆