Contents‎ > ‎

Implementing a Tree Structure Site in Drupal Using Taxonomy

Feb 2009

Excellent how-to article (2007): Manipulating the Drupal Breadcrumb which may have become outdated due to developments in Drupal modules.

Ideally, three elements come together consistently in a tree-structured site:
  1. Navigation (menus)
  2. Breadcrumb path
  3. URL

Getting these elements to be consistent with one another across an entire site is not possible with Drupal out-of-the-box, and has long been an elusive exercise, often requiring multiple repeating/redundant actions to get right. The article linked above offers some ways of implementing this, but here's another approach.


One-time setup actions:
  1. Verify that the core Menu module is active.
  2. Install, activate, and set permissions for modules Pathauto (requires module Token) and Node Breadcrumb.
  3. Menus - define your (possibly nested) site/navigation structure using menus.
  4. Node Breadcrumb - no settings necessary under Site Configuration.
  5. Pathauto - under Site Configuration -> Pathauto -> Node Path Settings, use the [menupath] (or [menupath-raw]) replacement pattern for the appropriate page type(s), normally "Page". For example, [menupath-raw]/[title].

Recurring actions:
  1. When creating a new node, add your content Title and Body fields as usual.
  2. Note that URL Path Settings should have the Automatic alias checkbox checked.
  3. Under Menu Settings, hang the node under a menu item, giving it a menu title. This is the crux of the entire exercise.
  4. Click "Submit"


Here's what happens:
  • Conceptually, associating the node with a menu item causes it to be placed in a single location in your site's (tree) structure. That was the motivation of this exercise.
  • Module PathAuto makes sure that the page's URL is consistent with that location in the structure, e.g.
  • Module Node Breadcrumb does two things, only one of which can be guessed at by its name. First, it forces the display of the entire breadcrumb path from 'Home' through to the page name (i.e., overcomes Drupal's stupendously strange behavior of showing a page's breadcrumb as 'Home > Title' while ignoring any hierarchy in between). For example Home > Articles > How to do menus.
  • Module Node Breadcrumb, just as importantly, forces the primary and secondary navigation to remain active at the node level (again overcoming Drupal's behavior of extinguishing menus once one has drilled down to the node level). For example, it will give a CSS status of 'active' to both your Articles main menu tab and your How To sub-menu tab. Note this may requiring some tweaking in CSS, but at least the 'active' indicator is there.

That's it - just what we set out to do: consistency between a page's URL, navigation, and breadcrumbs.

Drawbacks to this method

  • The menu structure gets cluttered; you will have as many menu items as you have pages. A workaround to this would be to use module Node Breadcrumb's built-in capability to set rules as to which menu items are automatically associate with which pages. However, in practice this workaround requires setting up additional Drupal page types which don't serve any other real function.
  • A 'title' has to be inserted for both the node and the menu item, causing redundancy. But at least this redundancy occurs in one place - the node edit screen - whereas alternative methods require redundancy in two (or more) different places.


Try this exercise using taxonomy_menu instead of node_breadcrumbs, to see if fewer steps are required