How to List Drupal Child Terms on Taxonomy Pages with Views

I spent a good amount of time at Monday's evening to actually figure this out. In today's Drupal Tutorial - How to List Drupal Child Terms on Taxonomy Pages with Views.

This issue has been on my table for about two years.

For the ease of this tutorial - here is basic setup. For a content type blog I have created pre-defined vocabulary - Category. Most of the category items are not related and are in linear format. But few of them are related and I have listed them as child terms.

Pre-defined category in Drupal

Pre-defined category in Drupal

The tricky part is how to display child terms under parent taxonomy page - let's say a visitor is visiting parent category page - Tourism Objects and we would like to feature a little sub-menu with child terms, like airports, shopping venues e.t.c.

I tried many modules and solutions, but decided to stick with a simple views configuration using attachment feature.

Drupal taxonomy page views to list child terms

In following example I have actually extended a little bit usability by displaying count for each child term using aggregation.

Open your taxonomy/term/% view and add a new attachment.

Give it a nice name, Child terms, for example. 

Start by adding a contextual filter:

  • Taxonomy Term:Parent term
  • Provide default value: Taxonomy Term ID from URL
  • Load default filter from term page

Relationships:

  • Content: Taxonomy terms on node
  • Require this relationship

Other:

  • Use aggregation: Yes

Format:

  • Format: Unformatted
  • Show: Fields

Fields:

  • Taxonomy term (name)
  • Taxonomy term (tid)
  • Global: Custom

Paste following in Custom field:

<div class="tax-menu">[name] <span class="small"> ([tid])</span></div>

were tax-menu and small are a div classes you can latter use for styling your sub-menu

Sort criteria:

Make sure you remove date, cause it will break things if you have enabled aggregation

  • Taxonomy Term ID, use aggregation Count

Attachment settings:

  • Attach to: Page
  • Attachment position: before

Save your view, and you should be done with technical stuff. Now it is time to apply some CSS. Here is what I got at the result:

Listing child terms on Drupal taxonomy page

Listing child terms on Drupal taxonomy page

Using similar approach (attachment) I have attached taxonomy term description and even Google Maps to my category pages.

 

Receive weekly trade ideas and portfolio adjustments directly to your inbox.

I share ongoing portfolio progress with a focus on generating income through covered calls on quality stocks. Each update includes positioning changes, trade rationale, and forward-looking adjustments based on current market conditions.

Latest blog

New Synagogue Berlin

The New Synagogue in Berlin is one of the city’s most recognizable historical landmarks, located on Oranienburger Straße, within walking distance of Alexanderplatz. Its striking golden dome rises above the surrounding buildings, making it visible from afar and hard to miss even during a casual walk through the neighborhood.Originally inaugurated…

Germany |
Embedded thumbnail for Book Reading Afternoon in Tbilisi

Book Reading Afternoon in Tbilisi

At the start of March, it was Book Week at the British International School of Tbilisi. Year 3 students were given a fun assignment: create a short video about their favourite book and take photos of themselves reading in unusual places.We slightly misunderstood the task and ended up focusing entirely on reading in unusual places, turning it into…

Living in Georgia |