Taxonomy Views Browser of Arbitrary Depth
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:
- Create a view of nodes
- Add relationship to taxonomy term (Term)
- Add relationship to taxonomy term parent, accessible via Term (Parent)
- Add relationship to taxonomy term parent, accessible via Parent (Parent Parent)
- Repeat step 4 as many times as necessary for your taxonomy’s depth.
- 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.
- 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:
- Put add a new top-level term (Foo) to your vocabulary and put all other terms under it.
- Create a view of terms with a page that displays term names
- Add contextual filter: Taxonomy term: Parent term
- When the default value is not in the URL, provide default value
- Set default value to your top-level term name (Foo)
- Specify validation criteria
- Validator: taxonomy term
- Criteria: your vocabulary name
- Filter value type: Term name converted to term ID
- Click the “+Add” button at the top of the Views panel to add an Attachment to the view.
- Add to this attachment only (override) Relationship: Taxonomy term: Content with term
- Add to this attachment only (override) display: fields: node titles linked to nodes, and remove (from this attachment only!) display: fields: term name
- 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)
- 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.