我有 3 个级别的 child 分类。我需要通过父级 tid 获取所有级别的子级。
taxonomy_get_children($tid) - 仅给出特定 $tid 的直接子级。但不是所有的孙子。
我该如何处理这个问题?
谢谢
最佳答案
function taxonomy_get_children_all($tid, $vid = 0, $key = 'tid'){
$c = taxonomy_get_children($tid, $vid, $key);
$result = array();
foreach ($c as $t => $d){
$result[$t] = $d;
$below = taxonomy_get_children_all($t, $vid, $key);
if (!empty($below)) {
foreach ($below as $nt => $nd){
$result[$nt] = $nd;
}
}
}
return $result;
}
关于drupal - 如何在drupal中获取所有分类子ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21986633/