Show Drupal Content Only With Terms of Specific Depth

Show Drupal Content Only With Terms of Specific Depth
Is it possible to allow Views to show only content that has child terms from a taxonomy?

Yes, it is. This is similar but slightly different to our tutorial on using Views to show only child terms.

First, you need to have your site set up correctly. You will need:

  • A taxonomy that has parent and child terms, as in this example below.
  • A content type that uses this taxonomy as a “Term reference” field.
  • Content that is tagged with these taxonomy terms.
A Drupal taxonomy with child terms

Let’s show you how to set up Views so that only content with child terms. In this example, the content needs terms such as Amphibians, Birds, Fish, Mammals, Reptiles.

  • Go to Structure > Views > Add new view.
  • Create a View that shows Content of the type that you want to show:
Creating a new view to show content with child terms
  • Click “Add” next to Relationships.
Adding a relationship to Views in Drupal
  • Search for “Content: Taxonomy terms on node”:
Adding Content: Taxonomy terms on node to Views
  • Choose your taxonomy.
  • Click “Apply (All displays)” to save your relationship.
Choosing a taxonomy in a Views relationship
  • Click “Add” next to Filter Criteria.
Adding a filter criteria to Views
  • Search for “Content: Has taxonomy terms (with depth)”.
  • Click “Apply (All displays)”.
with-depth
  • Choose your Vocabulary.
  • Choose “Depth”. For second-level terms (as in this example), choose “1”.
  • Click “Apply (All displays)”.
vocab
  • Under “Select terms from vocabulary”, choose a parent term. In this example, we choose “Vertebrates”.
parent terms
  • Save the filter and save your view.
  • You should now see that the parent terms are ignored:
A Drupal view showing only content with a child term

Author

  • Steve Burge

    Steve is the founder of OSTraining. Originally from the UK, he now lives in Sarasota in the USA. Steve's work straddles the line between teaching and web development.

0 0 votes
Article Rating
Subscribe
Notify of
3 Comments
Oldest
Newest
Inline Feedbacks
View all comments
najib elaz
najib elaz
6 years ago

my friend you save my day awsome i was looiking for this more than 24 hours in stackoverflow

kfcheng
4 years ago

This is excellent.  Something I have been looking for months.  Thanks.

mikall
4 years ago
Reply to  kfcheng

We are so glad that you found what you needed here.

3
0
Would love your thoughts, please comment.x
()
x