You are here

Taxonomy Menu

The taxonomy menu module provides a nice menu built from taxonomy structures. If you use the Drupal taxonomy system and want menus, install taxonomy_menu.

Install

Download from drupal.org/project/taxonomy_menu.

This is based on Taxonomy Menu for Drupal 4. Taxonomy Menu for Drupal 6 is a complete rewrite and there is a version 3 for Drupal 6 that is another complete rewrite.

  1. Download taxonomy_menu-4.6.0.tar.gz.
  2. Expand the downloaded file.
  3. Copy directory taxonomy_menu in to drupal/modules and web/modules.
  4. Go to administer > modules and switch on taxonomy_menu.
  5. Go to administer > settings > taxonomy_menu and look at the settings. You can switch vocabularies on and off.

The menu works. Now you need a node per vocabulary and a node per term. Module Vocabulary Node provides the node for the vocabulary and the Taxonomy Assoc module provides the node per term.

Settings

Display Descendants

Administer > settings > taxonomy_menu
Switch off the setting labelled Display descendants. When the option is on, taxonomy menu floods the page content with teasers for all descendants of the current page including the immediate children and the grandchildren. In a big site you get lots of confusing entries in the list.

When you switch the option off, the list is restricted to the children of the current page. This is the best option when you have a site structured several levels deep. If you have vocabulary Beer containing the terms Ale, Lager, Pilsener, and then children and grandchildren, the structure might look like the following list.

  • Beer
    • Ale
      • Pale
        • Australian
        • English
      • Amber
      • Brown
      • Black
    • Lager
    • Pilsener

When you view the Ale page with Display descendants on, you see the following list.

  • Pale
  • Australian
  • English
  • Amber
  • Brown
  • Black

When you view the Ale page with Display descendants off, you see the following list.

  • Pale
  • Amber
  • Brown
  • Black

Vocabularies

You get a list of vocabularies with an option to turn each vocabulary on or off.

Dependencies

Taxonomy menu uses the Taxonomy module. The taxonomy module is supplied as a standard part of Drupal and can be switched on in Administer > modules. Taxonomy menu uses some of the functions defined in the taxonomy module which means the taxonomy menu module will produce code errors if the taxonomy module is switched off.

Tables

taxonomy_menu uses the url_alias table. All other data is accessed by calls to functions in other modules.

Modifications

Display Sequence

Taxonomy menu uses the Taxonomy module to help produce the descendant list for a page. The taxonomy module defaults to sorting the list by the node sticky indicator and then the date of creation in a descending order. I find the best sequence is ascending alphabetical order to match the menus and the indexes in book pages. I modified an SQL statement in the taxonomy module to return the list in the right order.

Taxonomy taxonomy_select_nodes() sorts entries by n.sticky desc, n.created desc. Taxonomy menu displays menu entries in alphabetical order. I modified Taxonomy to sort the same using n.sticky desc, n.title. Perhaps the option could be a configuration setting. I suggested the modification for an administration setting in the taxonomy module but it was rejected. :-(

An alternative is to add code to the taxonomy menu module to sort the entries before display.

drupal_get_path_map

Bootstrap.inc contains function drupal_get_path_map() to get a list of url aliases from table url_alias. There are entries for some nodes as both node/13 and taxonomy_menu/2/4. To make the taxonomy menu entry override the other entry, I changed the SQL from select * from {url_alias} to select * from {url_alias} order by src.

Update url_alias

I decided there was too much work manually creating URL aliases so I wrote a quick change to create the alias. I submitted the change for consideration in drupal.org/node/30753.