2012-06-11 32 views
0

我嘗試打印使用此代碼的分類術語:如何在Drupal中打印分類術語?

<?php foreach ((array)$taxonomy as $item) { ?> 
<a href="<?php print base_path() . "taxonomy/term/" . $item->tid; ?> "class='tags'><?php print $item->name ?>,</a> 
<?php } ?> 

它工作在傳情精細,但它在整個節點犯規,標籤是在整個節點空。任何人都可以告訴我這是什麼原因以及如何解決這個問題?

+0

你可以給這個代碼的情況下? $ taxonomy從哪裏來? – nmc

+0

它存儲在$ node-> taxonomy中。 – nikunj

+0

你使用的是什麼版本的drupal?,你在哪裏添加了你上面提到的代碼? – Andre

回答

0

我意識到這是一個老問題,但我想發佈我的Drupal 6解決方案。

使用此

$tree = taxonomy_get_tree($vid); 

然後依次通過它打印出來的術語:

 foreach ($tree as $term) { 
     $path = taxonomy_term_path($term); 
     $content .= '<a href="<?php print base_path() . strtolower(str_replace(" ", "-",$term->name)) . '">' . $term->name . '</a>';   
    } 
相關問題