【问题标题】:Drupal's category (taxonomy) name of article (node)?Drupal的文章(节点)的类别(分类)名称?
【发布时间】:2011-06-30 17:44:30
【问题描述】:

开发我的自定义 Drupal 主题。它将包含自定义 node.tpl.php 文件。

如何获取和打印所选节点的相关分类名称?

Tnx in adv!

【问题讨论】:

    标签: drupal-7 taxonomy drupal-taxonomy


    【解决方案1】:

    编辑:Doh,我很抱歉,我刚刚看到 Drupal 7 标签,特别是。看来这个帖子有一些可能的解决方案:http://drupal.org/node/909968

    使用 D6(不是 100% 关于 D7)在节点的模板 .php 文件中(类似地,在视图中或大多数可以使用自定义 PHP 访问节点属性的位置,例如视图或块),您可以使用以下:

    // returns array of taxonomy objects for given node
    $tax_terms = taxonomy_node_get_terms($node);
    
    // prints each term name
    foreach ($tax_terms as $tax) {
        print $tax->name;
    }
    

    此外,还有一些有用的 Drupal 函数可用于以下情况:

    // print_r's all properties of a given node, similar to devel
    dpr($node);
    
    // using this in the above 'for' look will give you all properties of each taxonomy object
    dpr($tax);
    

    Here's a website 列出了更多这些函数。

    【讨论】:

      猜你喜欢
      • 2021-12-24
      • 1970-01-01
      • 1970-01-01
      • 2019-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多