我正在使用Joomla 3.2.3开发一个网站,在那里我一直在其中向我的Joomla文章添加一些标签,在文章中显示在它的内容之上。

对于列表,我使用“菜单项类型:文章>类别列表”,我想在列表中显示文章标签,例如,像这样:

[标题] [作者] [标签]

由于Joomla不支持文章管理器选项中的此选项以在列表布局中显示标记,我一直在尝试通过编辑列表布局文件来将其添加到列表中。 在这里,我制作了一个模板覆盖:

com_content>类别

其中包含列表文件:

  • default.php
  • default.xml
  • default_article.php
  • default_children.php
然后我尝试修改此文件,该文件创建列表布局:

... / templates / my_template / html / com_content / category / default_articles.php

要为列表布局创建标记列 - 我在第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; ?>
.

此创建并在“我的类别列表视图”中创建并显示了标题标题的第2列:标签(如果在文章管理器选项中设置为“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变量是正确的。

您将其放在代码内,以在列表上的单个项目的布局中的含义,其含义在标题之后。

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top