Taxonomy Views Browser of Arbitrary Depth

Posted by bbinkovitz on 2012.08.11 @ 15:12

Filed under:

Here’s a way to create a View (Drupal 7, Views 3.x) that lets you browse an arbitrarily-deep taxonomy hierarchy. With this type of browser you can link, oh, say, a large collection of videos, or photo galleries, or any kind of huge list of content categorized in a nested tree.

First, an simple static taxonomy term browser:

Static Depth Browser

This will give you nice paths and breadcrumbs (e.g. vocab » parent » term) For a taxonomy of static depth, you would do the following:

  1. Create a view of nodes
  2. Add relationship to taxonomy term (Term)
  3. Add relationship to taxonomy term parent, accessible via Term (Parent)
  4. Add relationship to taxonomy term parent, accessible via Parent (Parent Parent)
  5. Repeat step 4 as many times as necessary for your taxonomy’s depth.
  6. Add contextual filters for each one and make sure they’re in the proper order. Set to display a summary when filter is not in URL.
  7. You’ll probably want to override the breadcrumb and title for each filter.

Variable Depth Browser

For a taxonomy of variable depth, it’s a bit more complex:

  1. Put add a new top-level term (Foo) to your vocabulary and put all other terms under it.
  2. Create a view of terms with a page that displays term names
  3. Add contextual filter: Taxonomy term: Parent term
  4. When the default value is not in the URL, provide default value
  5. Set default value to your top-level term name (Foo)
  6. Specify validation criteria
    • Validator: taxonomy term
    • Criteria: your vocabulary name
    • Filter value type: Term name converted to term ID
  7. Click the “+Add” button at the top of the Views panel to add an Attachment to the view.
  8. Add to this attachment only (override) Relationship: Taxonomy term: Content with term
  9. Add to this attachment only (override) display: fields: node titles linked to nodes, and remove (from this attachment only!) display: fields: term name
  10. Add to this attachment only (override) contextual filter: Taxonomy term: Name
  11. When filter value is not available, provide default value: Raw value from URL: Path component: 2 (or more if your Page path has >1 component)
  12. Attachment settings: Attach to: [name of the page display you just made]

It’s not perfect — it doesn’t generate a nice URL and breadcrumb with the taxonomy lineage the way that my solution for a taxonomy of a single depth would do. The Path Breadcrumbs module is the tool you’ll want to use for this.


Cross-posted on Drupal Stack Exchange.

I am quite new to drupal and I am unable to get these lines

  1. Add to this attachment only (override) Relationship: Taxonomy term: Content with term
  2. Add to this attachment only (override) display: fields: node titles linked to nodes, and remove (from this attachment only!) display: fields: term name
  3. Add to this attachment only (override) contextual filter: Taxonomy term: Name When filter value is not available, provide default value: Raw value from URL: Path component: 2 (or more if your Page path has >1 component)
  4. Attachment settings: Attach to: [name of the page display you just made]

Can you please explain in some low level

Attachment” is a type of view display. When you click “add” to add a new display to your view, then you should see “attachment” as one of the display type options.

Add to this attachment only (override)” means make that setting on the attachment, and in the select box where it offers you options to set it on all displays or only on that one, select that one only.

Adding a relationship can be done under the “advanced” tab of the Views UI. This may be a collapsed fieldset that needs to be expanded by clicking before the advanced settings options are visible.

After you add the relationship, it will ask you what kind to add. There are many types in the list. On each step that specifies a relationship, select the options listed in the step. So Relationship: Taxonomy term: Content with term” means that you select the option to add a relationship, then you tell it that the relationship type is “taxonomy term” and then you select “content with term” from the list of taxonomy term-type relationships.

Contextual filters are right above relationships in that right-hand section where the advanced settings live. They are added and selected very similarly to relationships.

Attachment settings are set in the middle column of the views UI, when editing an attachment display.

There is now a screenshot on Drupal Answers Stack Exchange.