2011-06-03 66 views
1

我有一個分類父TID「8」如何讓分類兒童ID在Drupal

我需要讓所有的孩子TID這個父ID

$tid = 8; 

$children = taxonomy_get_children($tid); 

print_r($children); 

正在此結果

8 

Array 
(
[9] => stdClass Object 
    (
     [tid] => 9 
     [vid] => 3 
     [name] => Domestic 
     [description] => Domestic 
     [weight] => 0 
    ) 

[12] => stdClass Object 
    (
     [tid] => 12 
     [vid] => 3 
     [name] => Economic 
     [description] => Economic 
     [weight] => 1 
    ) 

[11] => stdClass Object 
    (
     [tid] => 11 
     [vid] => 3 
     [name] => International 
     [description] => 
     [weight] => 2 
    ) 

[10] => stdClass Object 
    (
     [tid] => 10 
     [vid] => 3 
     [name] => Social 
     [description] => 
     [weight] => 3 
    ) 

) 

如何只顯示此數組中的tid。

回答

4
$children = array_keys(taxonomy_get_children($tid)); 

你會發現它是一個關聯數組,其中在對象中的TID相同的數組鍵 - 只要抓住關鍵,它等同於對象本身抓住TIDS。