列出Drupal taxanomy术语

时间:2015-10-13 15:40:05

标签: drupal-7

我想将词汇表列为以下格式

<ul id="vid1">
<li>term1</li>
<li>term2
  <ul>
    <li>term2-child1</li>
    <li>term2-child2</li>
  </ul>
</li>
<li>term3
  <ul>
    <li>term3-child1</li>
    <li>term3-child2</li>
  </ul>
</li>
</ul>

如何修改以下代码以满足我的要求

<?php
$vid = 1; 
$terms = taxonomy_get_tree($vid); 
print_r($terms);
echo "<ul>";
foreach ( $terms as $term ) {
$count = db_query("SELECT COUNT(nid) FROM {taxonomy_index} WHERE tid = :tid ", array(':tid' => $term->tid))->fetchField();
print "<li>".$term->name." (".$count.")</li>";
}
echo "</ul>";
?>

1 个答案:

答案 0 :(得分:0)

$vid = 1;

$tree = taxonomy_get_tree($vid);
print '<ul id="vid1">';

foreach($tree as $key=>$term) {
 if($term->parents[0]==0) {
  print '<li>'.$term->name;

  $childrens = taxonomy_get_children($term->tid);
  print '<ul>';

  foreach($childrens as $children) {
    print '<li>'.$children->name.'</li>';
  }
  print '</ul></li>';
 }
};

print '</ul>';