欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

taxonomy_get_children 得到子分类

shiping1 的头像
7 taxonomy.moduletaxonomy_get_children($tid, $vid = 0)
4.6 taxonomy.moduletaxonomy_get_children($tid, $vid = 0, $key = 'tid')
4.7 taxonomy.moduletaxonomy_get_children($tid, $vid = 0, $key = 'tid')
5 taxonomy.moduletaxonomy_get_children($tid, $vid = 0, $key = 'tid')
6 taxonomy.moduletaxonomy_get_children($tid, $vid = 0, $key = 'tid')

Find all children of a term ID.

1 call to taxonomy_get_children()

File

 

modules/taxonomy/taxonomy.module, line 812
Enables the organization of content into categories.

Code

function taxonomy_get_children($tid, $vid = 0, $key = 'tid') {
  if ($vid) {
    $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_data} t INNER JOIN {term_hierarchy} h ON h.tid = t.tid WHERE t.vid = %d AND h.parent = %d ORDER BY weight, name', 't', 'tid'), $vid, $tid);
  }
  else {
    $result = db_query(db_rewrite_sql('SELECT t.* FROM {term_data} t INNER JOIN {term_hierarchy} h ON h.tid = t.tid WHERE parent = %d ORDER BY weight, name', 't', 'tid'), $tid);
  }
  $children = array();
  while ($term = db_fetch_object($result)) {
    $children[$term->$key] = $term;
  }
  return $children;
}

Comments

The $key parameter will be a key of returned children array. For example, if you have:

1 -> fruit
12 -> apples
13 ->  bananas

taxonomy_get_children(1, $vid, 'tid') will return:

<?php
$children
= array('12' => $termobject, '13' => $termobject2);
?>

taxonomy_get_children(1, $vid, 'name') will return:

<?php
$children
= array('apples' => $termobject, 'bananas' => $termobject2);
?>
来自 https://api.drupal.org/api/drupal/modules!taxonomy!taxonomy.module/function/taxonomy_get_children/6

 
普通分类: