【问题标题】:How to print taxonomy terms in Drupal?如何在 Drupal 中打印分类术语?
【发布时间】:2012-06-11 17:11:51
【问题描述】:

我正在尝试使用此代码打印分类术语:

<?php foreach ((array)$taxonomy as $item) { ?>
<a href="<?php print base_path() . "taxonomy/term/" . $item->tid; ?> "class='tags'><?php print $item->name ?>,</a>
<?php } ?>

它在预告片中工作正常,但在完整节点中没有,标签在完整节点中为空。谁能告诉我这是什么原因以及如何解决这个问题?

【问题讨论】:

  • 你能给这段代码更多的上下文吗? $taxonomy 来自哪里?
  • 它存储在 $node->taxonomy 中。
  • 你用的是什么版本的drupal?,你上面提到的代码是在哪里添加的?

标签: php drupal taxonomy drupal-taxonomy


【解决方案1】:

我意识到这是一个老问题,但我想发布我的 Drupal 6 解决方案。

使用这个

$tree = taxonomy_get_tree($vid);

然后循环打印出条款:

      foreach ($tree as $term) {
       $path = taxonomy_term_path($term);
       $content .= '<a href="<?php print base_path() . strtolower(str_replace( " ", "-",$term->name)) . '">' . $term->name . '</a>';           
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-27
    相关资源
    最近更新 更多