タクソノミー(taxonomy)を使っていると、 どんどん増やして次第に細分化して階層を分けることがでてくる。 そこで あああああ いいいいい ううううう みたいな横並びにタクソノミーの表示をさせたい。
現在Content Templatesで表示されるのが、こんな感じ。
- $node->taxonomy (array)
- $node->taxonomy[65] (object)
-
- $node->taxonomy[65]->tid
- 65
- $node->taxonomy[65]->vid
- 2
- $node->taxonomy[65]->name
- 欲しい物
- $node->taxonomy[65]->description
- $node->taxonomy[65]->weight
- 0
- $node->taxonomy[65]->v_weight_unused
- 0
- $node->taxonomy[206] (object)
-
- $node->taxonomy[206]->tid
- 206
- $node->taxonomy[206]->vid
- 1
- $node->taxonomy[206]->name
- スマホ
- $node->taxonomy[206]->description
- $node->taxonomy[206]->weight
- 0
- $node->taxonomy[206]->v_weight_unused
- 0
tid タームの番号 vid ボキャブラリーの番号 name タームの名前
一番上ので見ると、タクソノミーの中に 65というターム 2というボキャブラリー ほしい物という名前 となっている。
Grab the fourth value in the taxonomy array
個別で表示するには、下記の通りで表示ができる。
<?php foreach ($node->taxonomy as $tid
) {
if ($tid->vid == 4) // <-- the vocabulary id of the "brand"
$term_name = $tid->name;
}
print $term_name;
?>
これを参考にしながら
<?php foreach ($node->taxonomy as $tid) {
if ($tid->vid == 2) {
$term_name = $tid->name;
print $term_name;
} else {
print '';
}
}
?>
taxonomy as $tid) {
if ($tid->vid == 1) {
$term_name = $tid->name;
print $term_name;
} else {
print '';
}
}
?>
こんな感じにしてみました。
print '';