Reputation: 336
In Drupal 7 I have a categories taxonomy vocabulary with the following structure:
-Cat one -Cat two ---Sub cat two -Cat three
I added a node with the term Sub cat two
.
I created a view formatted as table, listing node names and its assigned categories.
In this view, the category field only shows Sub cat two
as result. As this term is a child of Cat two
, I'd like to show something like Cat two > Sub cat two
instead of just the child term.
I have no idea on how to achieve this.
Any hints? Thanks!
Upvotes: 0
Views: 881
Reputation: 336
That one was not and simple solution. I solved it this way:
In this view I created a new field of the type 'Global:PHP', and added the following to the "Value Code" textarea:
$n = node_load($data->nid);
$field = field_get_items('node', $n, 'field_tipo');
$parents = taxonomy_get_parents_all($field[0]['tid']);
$output = array();
foreach($parents as $term) {
array_unshift($output, $term->name);
}
return implode(' » ', $output);
And that's it!
Upvotes: 0