taxonomy flat lists
This is a real world example of using a series of flat taxonomy lists to categorize information. We'll be categorizing BMW car models and organizing them by car style and engine displacement. Since the car styles can get complex and car models can have more than one body style but we want don't want any cars listed more than once so we are going to use the flat lists I talked about. The other kind of lists go much deeper into Computer Science theory and data structures.
Before we go on, let's define the Drupal labels we'll be using. If you already know what a 'node', 'vocabulary', and 'term' is then skip the next couple paragraphs.
If you've used Drupal before there is a good chance you know that a 'node' is the basic piece of data. In a blog that would be one article, an ecommerce catalog it would be a product, a car dealership would probably have a car as a node. At least that was the way it was in Drupal5 and is in Drupal6. In Drupal7 and 8 things are getting a little more complicated but we won't worry about that right now.
In real life I keep track of 'groups' of things in my life (like all my friends, my family, my aquantances, etc). Each person is then a member of at least one of those groups. The stuffy word for organizing and categorizing things is "taxonomy". If you care about what the fancy word stands for then wikipedia has a good entry about it, but in Drupal all you have to know is that the native way to organize pieces of data is called 'taxonomy', groups of data are called 'vocabularies', and individual members of those groups are called 'terms'. In the industry, this kind of organization is called a "tag". Drupal just confuses this even more by only calling some terms tags (the ones that end-users set).
Now, let's organize cars by characteristics that are useful. It is easy to choose here because BMW's international corporation already has labeled cars (displacement, body style (SUV/sedan/coupe/Muscle car). All we have to do is make our database of cars match the labels in BMW's catalog.
The cars and their basic styles and engine displacement is listed below:
- 320 (a coupe with a 2.0 liter displacement)
- 330 (a coupe with a 3.0 liter displacement)
- 335 (a coupe with a 3.5 liter displacement)
- 340 (a coupe with a 4.0 liter displacement)
- M3 (a muscle car based on the coupe)
- X3 (an SUV based on the couple)
- 520 (an executive sedans with a 2.0 liter displacement)
- 530 (an executive sedans with a 3.0 liter displacement)
- 535 (an executive sedans with a 3.5 liter displacement)
- 540 (an executive sedans with a 4.0 liter displacement)
- M5 (a muscle car based on the executive sedan)
- X5 (an SUV based on the executive sedan)
As a side note, I'm only paying attention to a couple groupings because there are several that are no longer useful. Have you ever noticed that every model number has an 'i' behind it on a dealers floor or in a parts store catalog? The 'i' means it uses fuel injection yet all BMW cars have had fuel injection since the late 80s. So what most people call a '325' you'll find officially listed as a '325i'. And there are things that only apply in America (airbags), California (bumpers, additional O2 sensors, and unadjustable idle screws), and Europe (power steering). Some of those things are regulated by law and others are enforced by the market- I think most European prefer manual steering and think air-bags are only necessary when the rider is too stupid to click their seat-belt. And people say computers can get confusing.
So first we create the 2 vocabularies (groups) we are going to keep track of; body style, and displacement in the administration menu->-content management->-taxonomy->-vocabularies. We make sure the 'hierarical" option is not selected for either vocabulary. However, we select "multiple entries" for the vocabulary "body style" because there are some overlapping styles (SUV based on coupe, muscle car based on sedan, etc). We leave it blank for "displacement" since there is only one measurement for each model.
When you are finished the taxonomy structure will look like this table. Actually, this is just an example since the term ids will differ depending on how many taxonomy terms already exists in your system.
|body style||executive sedan||example.com/taxonomy/term/11||11|
|body style||muscle car||example.com/taxonomy/term/12||12|
|engine displacement||2.0 liter||example.com/taxonomy/term/14||14|
|engine displacement||3.0 liter||example.com/taxonomy/term/15||15|
|engine displacement||3.5 liter||example.com/taxonomy/term/16||16|
|engine displacement||4.0 liter||example.com/taxonomy/term/17||17|
Finally, when you enter the car node they are tagged with the body type and displacement like in this table.
|320||coupe style, 2.0 liter displacement|
|330||coupe style, 3.0 liter displacement|
|335||coupe style, 3.5 liter displacement|
|340||coupe style, 4.0 liter displacement|
|520||executive sedan style, 2.0 liter displacement|
|530||executive sedan style, 3.0 liter displacement|
|535||executive sedan style, 3.5 liter displacement|
|540||executive sedan style, 4.0 liter displacement|
|M3||coupe and muscle car styles|
|M5||executive sedan and muscle car style|
|X3||coupe and SUV styles|
|X5||executive sedan and SUV styles|
Then you could show only those cars that meet certain criteria by using a special URL. That URL can be pointed to by another website or internally with a menu item.
- If you want to see all coupes (320, 330, 335, 340, M3, X3):
- If you want to see all executive sedans (520, 530, 535, 540, M5, X5):
- If you want to see all muscle cars (M3, M5):
- If you want to see all SUVs (X3, X5):
- If you want to see all coupes that are also muscle cars (M3):
- if you want to see all coupes that are either SUV or muscle cars (X3, M3):