Many 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:
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:
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!