1
我試圖顯示來自節點的2個詞彙表的每個術語,但是我有這種情況。
我有2個詞彙表,像「品牌」和「汽車」的東西。Drupal顯示不同詞彙的所有詞條
- 品牌
- 福特
- BMW
- 奔馳
- 汽車
- 藍
- 淺藍色
- 紅
- 綠色
我的節點必須是即使在寶馬,甚至在「淡藍色」。
在我template.tpl我有這個功能:
function theme479_print_terms($node, $vid = NULL, $ordered_list = TRUE) {
$vocabularies = taxonomy_get_vocabularies();
if ($ordered_list) $output .= '<ul>'; //checks to see if you want an ordered list
if ($vid) { //checks to see if you've passed a number with vid, prints just that vid
$output = '<div class="tags-'. $vid . '">';
foreach($vocabularies as $vocabulary) {
if ($vocabulary->vid == $vid) {
$terms = taxonomy_node_get_terms_by_vocabulary($node, $vocabulary->vid);
if ($terms) {
$links = array();
$output .= '<span class="only-vocabulary-'. $vocabulary->vid . '">';
if ($ordered_list) $output .= '<li class="vocabulary-'. $vocabulary->vid . '">' . $vocabulary->name . ': ';
foreach ($terms as $term) {
$links[] = '<span class="term-' . $term->tid . '">' . l($term->name, taxonomy_term_path($term), array('rel' => 'tag', 'title' => strip_tags($term->description))) .'</span>';
}
$output .= implode(', ', $links);
if ($ordered_list) $output .= '</li>';
$output .= '</span>';
}
}
}
}
else {
$output = '<div class="tags">';
foreach($vocabularies as $vocabulary) {
if ($vocabularies) {
$terms = taxonomy_node_get_terms_by_vocabulary($node, $vocabulary->vid);
if ($terms) {
$links = array();
$output .= '<ul class="vocabulary-'. $vocabulary->vid . '">';
if ($ordered_list) $output .= '<li class="vocabulary-'. $vocabulary->vid . '">' . $vocabulary->name . ': ';
foreach ($terms as $term) {
$links[] = '<span class="term-' . $term->tid . '">' . l($term->name, taxonomy_term_path($term), array('rel' => 'tag', 'title' => strip_tags($term->description))) .'</span>';
}
$output .= implode(', ', $links);
if ($ordered_list) $output .= '</li>';
$output .= '</ul>';
}
}
}
}
if ($ordered_list) $output .= '</ul>';
$output .= '</div>';
return $output;
}
在我node.tpl,我有這樣的:
print theme_print_terms($node, $unordered_list = TRUE);
結果如下:
品牌:寶馬
顏色:淺藍色
c我得到如下的東西?
品牌:寶馬
顏色:藍色/淺藍色
因此,與每一位家長的類別。你可以幫我嗎?
編輯:
它可以顯示一個詞彙的所有層次?例如,我有一個詞彙結構(食品>水果> Fruit_with_seeds - >蘋果),但此功能只顯示水果> Fruit_with_seeds)
感謝它的工作! – Matteo 2011-04-21 15:33:15
它可以顯示詞彙的所有層次結構?例如我有一個詞彙結構(食品>水果> Fruit_with_seeds - >蘋果),但這個功能只顯示水果> Fruit_with_seeds) – Matteo 2011-04-28 15:12:43