【问题标题】:Drupal - Views - Taxonomy Term ID - custom template - anchorsDrupal - 视图 - 分类术语 ID - 自定义模板 - 锚点
【发布时间】:2013-12-30 17:58:12
【问题描述】:

快速版:如何在视图模板中输出分类术语 ID?我只想要数字 ID 值。这将用作链接锚。

长版:

场景,我有一个显示分类术语列表的视图。该视图有一个页面和一个块。页面视图设置为将块视图显示为标题。该块视图只包含分类名称。页面视图显示所有分类内容。

我希望阻止视图列表锚定到页面视图中的项目:

这个视图已经建立,等式中缺少的部分是让锚链接到位。

视图当前包含 3 个自定义模板文件:

views-view-fields--categories--page.tpl.php

<article id="NEED THE TERM ID HERE">
  <header>
    <h2 class="flag-heading"><?php print $fields['name']->content; ?> <span>in association with <?php print $fields['field_sponsor']->content; ?> </span></h2>
  </header>
  <div class="table">
    <div class="table-cell">
      <?php print $fields['field_category_image']->content; ?>
    </div>
    <div class="table-cell">
      <?php print $fields['description']->content; ?>
    </div>
  </div>
</article>

views-view-fields--categories--block.tpl.php

<li><a href="NEED THE TERM ID HERE"><?php print $fields['name']->content; ?></a></li>

views-view--categories--block.tpl.php

<ul>
    <?php print $rows; ?>
</ul>

我尝试在顶部块视图链接上使用视图上下文过滤器重写,但没有成功。

我需要的只是 TERM ID 的变量 - 我已经完成了可用变量的 var 转储,我可以在该列表中看到 TID,但不知道如何在 views-view-fields 中引用它模板文件,并且在网上找不到任何东西可以回答这个最简单的概念。

页面和块视图设置的屏幕截图:

【问题讨论】:

    标签: php drupal views taxonomy


    【解决方案1】:

    终于赢得了我的论点,即这个跳转列表完全是多余和愚蠢的,所以它会被删除,然而,我确实设法输出了 TID,这相当明显,因为这些事情通常是......

    views-view-fields--categories--block.tpl.php

    <li>
        <a href="#cat<?php print($view->result[$view->row_index]->tid); ?>"><?php print $fields['name']->content; ?></a>
    </li>
    

    views-view-fields--categories--page.tpl.php

    <article id="cat<?php print($view->result[$view->row_index]->tid); ?>">
      <header>
        <h2 class="flag-heading"><?php print $fields['name']->content; ?> <span>in association with <?php print $fields['field_sponsor']->content; ?> </span></h2>
      </header>
      <div class="table">
        <div class="table-cell">
          <?php print $fields['field_category_image']->content; ?>
        </div>
        <div class="table-cell">
          <?php print $fields['description']->content; ?>
        </div>
      </div>
    </article>
    

    变量显然在视图数组中,只是获取当前视图项的索引的一种情况。

    【讨论】:

      【解决方案2】:

      添加

      <?php print $fields['tid']->content; ?>
      

      应该在views-view-fields--xxx--page.tpl.php 和--block.tpl.php 中给你TID

      确保将字段设置为删除任何默认包装器,您应该一切顺利。

      【讨论】:

      • 最后是一个未定义的索引 - 尝试了这条路线,但还是谢谢。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多