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

时间:2014-06-03 10:01:26

标签: php listview joomla joomla3.0

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

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

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

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

com_content>分类

其中包括list-files:

  • 如default.php
  • default.xml中
  • default_article.php
  • default_children.php

然后我尝试修改此文件,创建列表布局:

... /模板/ my_template / HTML / com_content /类别/ 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; ?>

这创建并在我的类别列表视图中显示第二列,标题标题为: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; ?>

这是我需要帮助的代码,因为它不能完全发挥作用,它只在字段中显示文本'tags'(来自'JTAG'),并且不显示代码中的文章标记:

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

我从Articles视图的默认布局中看到了标签的呈现方式。 但是这个代码似乎并不直接在“类别”列表布局中起作用,或者不会产生任何影响。


试图看一下这篇文章: Article Tags shown in Article List-Layout

但是无法让这篇文章中的代码为我工作:

1 个答案:

答案 0 :(得分:0)

因此,如果您查看网站链接类别布局,您会看到使用此代码显示各个链接的标记:

<?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); ?>
相关问题