Views Taxonomy Term Name Depth

Provides Views contextual filter plugins that filter content by taxonomy term names with hierarchical depth support.

views_taxonomy_term_name_depth
8,597 sites
39
drupal.org

Install

Drupal 11, 10, 9 v7.3.1
composer require 'drupal/views_taxonomy_term_name_depth:^7.3'
Drupal 8 v7.0.2
composer require 'drupal/views_taxonomy_term_name_depth:^7.0'

Overview

The Views Taxonomy Term Name Depth module extends Drupal Views with specialized contextual filter (argument) plugins for taxonomy-based content filtering. Unlike core taxonomy filters that work with term IDs, this module allows filtering by human-readable term names, making it ideal for URL-friendly paths.

The module provides two key Views plugins: an argument handler that filters content by taxonomy term name with depth traversal (supporting both parent and child term hierarchies), and an argument default plugin that automatically extracts taxonomy parent IDs from the current page context.

Integration with the Pathauto module enables intelligent URL alias matching, allowing term names in URLs to match their actual taxonomy terms regardless of special characters or formatting differences. This makes the module particularly powerful for creating SEO-friendly, hierarchical taxonomy-based content listings.

Features

  • Views contextual filter (argument) plugin that filters content by taxonomy term NAME instead of term ID, enabling URL-friendly filtering
  • Hierarchical depth support with positive depth values to include child terms and negative depth values to include parent terms in the hierarchy
  • Integration with Pathauto module for intelligent URL alias matching using the alias cleaner service
  • Vocabulary filtering to restrict term matching to specific vocabularies, preventing conflicts when terms share names across vocabularies
  • Multiple value support allowing comma or plus-separated term names (1+2+3 format) for filtering by multiple taxonomy terms
  • Views argument default plugin that extracts taxonomy parent term IDs from current URL context (taxonomy term pages or node pages)
  • Related content blocks functionality by loading taxonomy references from the current node page
  • Cache-aware implementation with URL-based cache contexts for optimal performance

Use Cases

SEO-friendly category pages

Create views that filter content by URL-friendly taxonomy term names. For example, a URL like /products/electronics would filter products tagged with the 'Electronics' term, with Pathauto handling the URL alias conversion.

Hierarchical product catalogs

Build product listings where viewing a parent category (e.g., 'Clothing') automatically includes products from child categories ('Shirts', 'Pants', 'Accessories') by setting a positive depth value.

Parent category navigation

Create breadcrumb-style navigation or category landing pages where viewing a child term page (e.g., 'Smartphones') also shows content from parent categories ('Electronics', 'Technology') using negative depth values.

Related content blocks

Display related content blocks on node pages by using the Taxonomy term parent ID from URL argument default. The block automatically shows content sharing taxonomy terms with the current node.

Multi-vocabulary filtering

Filter content across specific vocabularies when the same term names exist in multiple vocabularies (e.g., 'News' as both a content type category and a news section topic).

Tag-based content aggregation

Allow multiple tag filtering via URL with the break_phrase option enabled, supporting URLs like /topics/drupal+php+web-development to show content tagged with any of those terms.

Tips

  • Use the Pathauto module for best results - it ensures URL aliases like 'web-development' correctly match terms named 'Web Development'
  • Set vocabulary restrictions when you have terms with identical names across different vocabularies to avoid unintended matches
  • Use positive depth values sparingly on large taxonomies as each depth level adds JOIN operations to the database query
  • The 'Allow multiple values' option treats AND as OR due to query complexity - use this for broad filtering rather than strict intersection
  • For related content blocks, combine the taxonomy_tpid argument default with appropriate caching strategies using the URL cache context
  • Test depth settings carefully - depth of 0 matches only the exact term, depth of 1 includes direct children, depth of 2 includes grandchildren, etc.

Technical Details

Hooks 1
hook_views_data_alter

Alters Views data to register the custom taxonomy_index_name_depth argument plugin for node content filtering.

Troubleshooting 4
Contextual filter not finding matching terms

Ensure Pathauto is installed and the term names in your URLs match the Pathauto-cleaned versions of your taxonomy terms. Check vocabulary restrictions if terms exist in multiple vocabularies.

Too many or too few results with depth filtering

Verify the depth value is set correctly. Depth 0 = exact match only, positive values include children, negative values include parents. Each increment adds one level of hierarchy.

Performance issues with deep hierarchies

Large depth values create multiple JOIN operations. Consider limiting depth to 2-3 levels or using vocabulary restrictions to reduce the query scope.

Multiple values not working as expected

When 'Allow multiple values' is enabled, AND operations are treated as OR. If you need strict AND filtering, consider using multiple contextual filters instead.