2

I am wondering about how to set up hierarchical taxonomies. For example say I have a vocabulary called Vehicle Make which consists of terms Audi and Honda, then I have a further vocabulary called Vehicle Model which consists of A4, Civic and Accord. So now say I wanted to create a vehicle registration content type with term reference fields corresponding to the two vocabularies listed above. Is there a way to define an is-a relationship between these vocabularies, I.E. an Accord is a Honda and an A4 is an Audi and therefore the selection in the Vehicle Model term reference would be dependent upon the selection in the Vehicle Make term reference. So if I select honda for the make I should be able to select Accord or Civic for the model and if I select Audi I should be able to only select A4. Is this something that can be done with Drupal taxonomy system?

2 Answers 2

3

Yes but they would not be 2 vocabularies, they would be hierarchical terms in 1 vocabulary, ex:

Cars
-Ford
 -Focus
 -F150
-Mazda
 -6
 -9
 -Protege

You can have infinite levels of parents.

This module would probably be a huge time saver for you: http://drupal.org/project/hierarchical_select

Edit: I should add that since Drupal 7 provides taxonomies as fieldable entities, you could very easily attach a "Car photo" field or the like to your "cars" vocabulary and achieve a lot of functionality rather quickly.

5
  • Thanks a lot. This seems to work in general but not completely. To continue our example, say we wanted filter based on Either Make or Model, if we added a filter criteria based on the Vocabulary you just described and then exposed this to the user then had a user create a content and select a Ford Focus. Now when they made this selection they really selected Focus (inside the Ford grouping), but now if we wanted to filter based on Ford it seems that it will not show the content that was just created (at least that was my experience). Is this correct? Anyway around it?
    – Mike2012
    Commented Feb 1, 2012 at 21:33
  • Also, do you know if there is any way to use a hierarchical_select as a filter criteria? It normally seems to only give me the option of a text field or a drop down menu (single drop down).
    – Mike2012
    Commented Feb 1, 2012 at 21:34
  • In the settings for Hierarchical Select you simply need to specify that, for this vocabulary on this node type, you want to save ALL levels and not just the deepest level, then this item will show for 'Ford' as well as 'Focus'. You can use it as a filter criteria by building a View and setting this vocabulary as an exposed filter, using Hierarchical Select as the widget type. Commented Feb 2, 2012 at 15:44
  • Sadly it seems that the you cannot use a hierarchical select as a widget in a view's filter in Drupal 7 (the functionality has not yet been ported).
    – Mike2012
    Commented Feb 6, 2012 at 18:45
  • @Mike2012: you should try this sandbox project: Views hst filter. This is really promising, I've already tried that, I hope it will get to a full release soon. You can see a demo here. This was very useful for one of my projects.
    – Sk8erPeter
    Commented Nov 23, 2012 at 21:04
5

You can construct your hierarchy using the core module taxonomy. Go to admin/structure/taxonomy, create your vocabulary and add your terms. The form that lists your terms precedes the name with a graphic arrow widget (points in four directions. Selecting that widget and dragging can reposition the terms in parent child relationships, and your done! The Taxonomy Manager module can help you add large quantities of terms to a vocabulary very quickly as well.

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.