Drupal 7: Flat Taxonomy Module

David G - DrupalMany websites I create make use of Taxonomies in Drupal as a means of Categorizing content found within the website. Often times the taxonomy terms assigned per Node are used to make contextual Views or expose filter options for a View on the website. While categorization of content is easily achieved by Drupal — sometimes we want to limit our Taxonomy Tree to a single level hierarchy and not allow our taxonomy trees to include nested terms. Until recently I had not found a simple solution to this problem.

Typical Taxonomy Usage in Drupal

Many websites I have created make use of Taxonomies. Example use cases include:

  • Year and Quarter entries for a Course content type.
  • Type(s) of job titles available within a system
  • A hierarchical listing of Regions in the World that offer educational programs.
  • Create a fake username field for a generic blog content type to denote an authors name.

Examples of live usages of the above example can be seen here:

Listing of hierarchical educational programs within Regions of the World, and then by Country.

Listing of hierarchical educational programs within Regions of the World, and then by Country.

Examples simple News categories for a generic News content type for a website.

Examples simple News categories for a generic News content type for a website.

Note that above the listing of countries and programs has so many nested entries the website makes use of the Taxonomy Manager module to better ease management of this large taxonomy.

Out of the box Drupal supports taxonomies but in all my examples thus far the handles in the taxonomy administration allow a site administrator to nest taxonomy terms. For the first example of the Programs in Countries nesting terms is a great feature of the site; but for the News categorization ideally a site administrator cannot nest these terms. They are in-effect a flat free-tagging set of terms.

Flat Taxonomy Module

So enter the Flat Taxonomy module. This module allows a site administrator to define per Taxonomy whether or not the included terms should be able to be nested or whether the taxonomy is forced to be flat.

This way if you’re building a website for a client (or yourself) and want to assure that business requirement that “News items should be assigned into 1 category” is easily enforced by Drupal and the default capability of allowing nesting, which relates a Node to both the child and parent term(s), is never allowed.

After enabling flat taxonomy you can create and try out making a taxonomy with constant depth:

You can assign a taxonomy as flat by marking it so in the admin.

You can assign a taxonomy as flat by marking it so in the admin.

Note than when adding a term to this taxonomy you may no longer assign a parent term to this new term, this enforces the ... flatness!

Note than when adding a term to this taxonomy you may no longer assign a parent term to this new term, this enforces the … flatness!

Lastly, if you try to reorganize your taxonomy tree through the Taxonomy Admin UI you will not be allowed to nest terms, but simply reorder them.

Lastly, if you try to reorganize your taxonomy tree through the Taxonomy Admin UI you will not be allowed to nest terms, but simply reorder them.

I hope you can see how useful this module can be your site and business logic! I’m adding to the list of modules I use when building projects.

Looking for quality web hosting? Look no further than Arvixe Web Hosting!

Tags: , , | Posted under Drupal | RSS 2.0

Author Spotlight

David Gurba

I am a web programmer currently employed at UCSB. I have been developing web applications professionally for 8+ years now. For the last 5 years I’ve been actively developing websites primarily in PHP using Drupal. I have experience using LAMP and developing data driven websites for clients in aviation, higher education and e-commerce. If you’d like to contact me I can be reached at david.gurba@arvixe.com

Leave a Reply

Your email address will not be published. Required fields are marked *