Article Tags shown in Article List-Layout

天大地大妈咪最大 提交于 2019-12-02 18:41:10

问题


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.


回答1:


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;

e.g.

<?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;
?>

I'm not sure what you're using $args for either, it could probably be removed, unless you're using somewhere else.



来源:https://stackoverflow.com/questions/19972885/article-tags-shown-in-article-list-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!