1

I'm outputtin taxonomy terms using Views; The field i'm calling up is 'Content: All taxonomy terms' and returning all the vocabulary 'address' . Views then puts these into alphabetical order ie.

England, London, Victoria

I'd like it to return from Parent downwards. Anyone know how to do this ?

Many thanks,

0

3 Answers 3

1

I believe you're looking for something like the Hierarchical Term Formatter module:

This module provides hierarchical term formatters for taxonomy reference fields. In other words, it can display a taxonomy term reference on, say, a node as Parent > Child, rather than just Child.

1
  • Unfortunately installing this on my existing Drupal site causes all the fields in any views that contain taxonomy to disappear :/ Shame as this would have been perfect.
    – Deejay
    Oct 27, 2014 at 18:00
0

If you are looking to order them BY ID, or NAME, or WEIGHT.

You need to create in Advance (Views) a Relationship pointing to that Taxonomy Vocabulary

Then you can add a Sort Filter, in the way you want...

5
  • Hi DarkteK I've tried with relationshiop 'Content: Taxonomy terms on node' > with my Vocabulary. And then in sort criteria 'Taxonomy term:Weight' . However this will attempt to order the results like this. not the output of the 'All taxonomy terms' field . My feeling is that it'll need to be a module that sorts this.
    – Deejay
    Oct 28, 2014 at 9:00
  • If you are using module: "Views PHP", just : 1. Add field 'All taxonomy terms' then "Exclude" from ur view 2. Add a "Global: PHP" field, just under the previous one 3. Edit that PHP Field with -> 'Value code' for this will be 'echo "1";' 4. Then the output code (You can check the variables avaliable for this). Once you choose your variable, for example ($row->field_areas_of_activity)just use PHP and order them with asort() Let me know if you can follow this
    – DarkteK
    Oct 28, 2014 at 19:20
  • Hi DarteK; Thanks for the reply. I follow this but at the point that i have $row->term_node_tid - which would be 'England, London, Victoria' I am unsure what PHP would be able to put that into Parent > Child order. Or does this return data I do not know about. Many thanks.
    – Deejay
    Oct 29, 2014 at 17:50
  • I can't help you more from here, I really would like to help you, but I don't know how ... sorry man
    – DarkteK
    Oct 30, 2014 at 1:59
  • No worries, thanks Darktek you've helped me enough to find an answer :) . I've managed to work out an SQL query that returns what I need. I'll post an answer when tested. Thanks again .
    – Deejay
    Oct 30, 2014 at 6:32
0

The following code takes the absolute child tid and grabs all parents. The second argument is for the amount of terms you wish to return; and the thrid for how you want to order it.

 /**
 * @file Orders Taxonomy
 *
 * @param $output - expecting a tid  // check this at the point of running the    function
 * @param $no_results - the number of results that you'd like to return
 * @param $order - which tid first - child or most senior parent ?
 */

 function taxonomy_order($output, $no_results = 1, $order = 'first') {

  $terms = entity_load('taxonomy_term', array($output));
  $wrapper = entity_metadata_wrapper('taxonomy_term', $output);
  $all_parents = $wrapper->parents_all->value();

  ( $order == 'last' ) ? $all_parents = array_reverse($all_parents) : $all_parents;

  $stitch_term_array = '';
  foreach ($all_parents as $key => $term) {
   ($key < $no_results ) ? $stitch_term_array .= $term->name . ", " : '';
   }
  $stitch_term_array = rtrim($stitch_term_array, ', ');

  return $stitch_term_array;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.