【问题标题】:Display Drupal taxonomy tree显示 Drupal 分类树
【发布时间】:2015-03-09 05:08:48
【问题描述】:

我通过此代码成功打印了整个分类树
$voc = taxonomy_vocabulary_machine_name_load('product_sub_categories'); $tree = taxonomy_get_tree($voc->vid,0,NULL,TRUE); foreach ($tree as $key => $term){ print $term->name."</br>"; } ,现在我想分别打印 parent 和 chile 以自定义主题,因为我已经有一个标记,其中 parent 有单独的 &lt;p class="parent_class"&gt;Parent terms&lt;/p&gt; 和孩子有单独的
&lt;ul class="child_class"&gt;Child terms&lt;/ul&gt;。 我该怎么做,有人可以帮助我吗?

【问题讨论】:

    标签: drupal-7 taxonomy


    【解决方案1】:

    解决办法

    `$tree=taxonomy_get_children(1);
    foreach ($tree as $term)
    {
    $item[] = $term->name;
    $child_term = taxonomy_get_children($term->tid);
    if (!empty($child_term))  
    {
    print $term->name."<br>";
    foreach ($child_term as $child) 
    {
    print $child->name."<br>";
    }
    }
    else 
    print $term->name."<br>";
    }`
    

    【讨论】:

      【解决方案2】:

      您可以使用Views Tree 模块。

      这里是这个模块的文档 https://www.drupal.org/node/1493366

      【讨论】:

      • 谢谢@uzma,但由于某种原因我必须通过api函数获取它,我也得到了答案。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-27
      • 1970-01-01
      • 2016-06-02
      • 1970-01-01
      • 2013-09-14
      • 1970-01-01
      相关资源
      最近更新 更多