在类别列表布局中显示文章标签


Show Article Tags in the Category List Layout

我正在使用joomla 3.2.3开发一个网站,我已经在我的joomla文章中添加了一些标签,这些标签在文章中显示在它的内容上方。

对于列表,我使用"菜单项类型:文章>类别列表",我想让它在列表中显示文章标签,例如:

[Title] [Author] [Tags]

由于joomla不支持文章管理器选项中的这个选项来在list - layout中显示标签,我一直在尝试通过编辑list - layout文件将其添加到列表中。这里我做了一个模板覆盖:

com_content>目录

包含列表文件:

  • default.php
  • default.xml
  • default_article.php
  • default_children.php
然后我试着修改这个文件,它创建了list-layout:

…/模板/my_template/html/com_content/类别/default_articles.php

为了创建list-layout的标签列,我在第100行左右的部分添加了以下代码:
<?php if ($this->params->get('show_tags')) : ?>
   <th id="categorylist_header_tags">
         <?php echo JHtml::_('grid.sort', 'JTAG', 'tags', $listDirn, $listOrder); ?>
   </th>
<?php endif; ?>

这在我的分类列表视图中创建并显示了第二列,标题为:Tags(如果在文章管理器选项中设置为'show')

为了在列字段中显示标签,我认为我需要在第181行周围的部分中为标签添加代码,我尝试添加以下代码:

   </td>
<?php endif; ?>
<?php if ($this->params->get('show_tags', 1)) : ?>
   <<td headers="categorylist_header_tags" class="list-tags">
      <?php $this->item->tagLayout = new JLayoutFile('joomla.content.tags'); ?>
      <?php echo $this->item->tagLayout->render($this->item->tags->itemTags); ?>
         <?php echo JText::sprintf('JTAG', $article->tags->itemTags); ?>
   </td>
<?php endif; ?>

这是我需要帮助的代码,因为它不完全工作,它只显示文本'标签'(来自'JTAG')在字段中,不显示文章的标签从代码:

<?php $this->item->tagLayout = new JLayoutFile('joomla.content.tags'); ?>
<?php echo $this->item->tagLayout->render($this->item->tags->itemTags); ?>

,我从文章视图默认布局中取出来看看标签是如何呈现的。但是这段代码显然不能直接在类别列表布局中工作,或者没有任何效果。


试着看看这篇文章:文章标签显示在文章列表-布局

但是还没能得到这篇文章中的代码为我工作:

如果你看一下weblinks的分类布局你会看到每个链接的标签都是这样显示的

<?php $tagsData = $item->tags->getItemTags('com_weblinks.weblink', $item->id); ?>
<?php if ($this->params->get('show_tags', 1)) : ?>
    <?php $this->item->tagLayout = new JLayoutFile('joomla.content.tags'); ?>
    <?php echo $this->item->tagLayout->render($tagsData); ?>
<?php endif; ?>

所以你需要做的是正确地设置$tagsData,改变别名,并确保id变量是正确的。

您将其放入列表中单个项目的布局代码中,意思是在blog_item.php文件中,可能就在标题之后。

    <?php $this->item->tagLayout = new JLayoutFile('joomla.content.tags'); ?>
    <?php echo $this->item->tagLayout->render($this->item->tags->itemTags); ?>