2009
12.26

When you hear the word “taxonomy” for the first time while trying to grasp what Drupal is about, it might look like a problem impossible to tackle. A major in science might help with the meaning of the word but nothing more. However, soon afterwards, you realize that it is not so difficult, you just need to use it properly and sometimes intelligently.

Sometimes when you get comfortable with the notion, it is easy to forget some easy tricks. Here is two of them that are related to parent/child relationship of taxonomy terms.

  • To show a term AND its children you can use Taxonomy: Term ID (with depth) option in the arguments section of the view that you are building.

To show the nodes belonging to a term you use:
taxonomy/term/x — where x is the term id to show, a number.

However, to show children nodes you need to add a depth variable. The syntax is:
taxonomy/term/x/y — where x is the term id to show, and y is the depth to go below x.

An example will explain this better. Let’s assume you have a structure such as this:

America (tid=1)
–Canada (tid=3)
–United States (tid=4)
—-Texas (tid=9)
——Amarillo (tid=11)
——Austin (tid=12)
—-California (tid=10)
——Los Angeles (tid=14)

If you use taxonomy/term/1, you’ll see only entries catalogued only under America (tid=1), but not its children.

If you use taxonomy/term/4/1, you’ll see entries for United States (tid=4) and its children to a depth of one; that is, you’ll see entries catalogued under Texas (tid=9) and California (tid=10).

If you use taxonomy/term/4/2, you’ll see entries for United States (tid=4) and its children to a depth of two; that is, you’ll see entries catalogued under Texas (tid=9) and California (tid=10) [this is the first level of depth], but also entries catalogued under Amarillo (tid=11), Austin(tid=12) and Los Angeles(tid=14).

Comments are closed.