Question

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!

Was it helpful?

Solution

That one was not and simple solution. I solved it this way:

  1. I first installed Views PHP module and enabled it;
  2. I created a content view for my content type formatted as a table;
  3. 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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top