0

How to set up a view that displays all terms for a specific taxonomy including the ones that have no content assigned?

I just can't figure it out to do it with a view:CONTENT and mainly found posts about hiding them.

In the results table, I also want to show a count of # nodes for each term (which I managed to do with Aggregation > Count).

I also tried creating as a View:TERM which does list all terms associated but then I can't display a count of nodes for it.

0

If the goal is to also show terms that have no content related to them, it doesn't make sense to start with the Content Views. How could you get terms information from non-existing relations? You could code a custom solution for that, logic that pulls out all terms and if no nodes are tagged display zero.

But there are ways to go forward with core Views.

Display node count on Terms nodes

  1. Create Views of type Taxonomy term displaying terms for the Vocabulary you want
  2. Add a Relationship Content using field_yourtaxreffield
  3. You should already have the Taxonomy field, now add a new Field Title (or NID) and set it to use the Relationship from the previous step (to show nodes titles)
  4. Turn Aggregation on
  5. Edit the Aggregation settings on the Title field, change it to Count DISTINCT. Now you should be able to see the counts, next to all the terms from your chosen vocabulary, including the one with 0 nodes.
  6. (Optional) you can Override the output of this field with custom text to place the count in brackets. The Text might be something like ({{ title }}), check under Replacement patterns

The problem here is extending this result to list node titles. Adding another content related field messes up the Aggregation results because it breaks them into separate rows and count becomes meaningless in that context.

I don't know if there is a clever way to solve it without an additional module. Maybe someone else can come in with the solution.

If using more modules is ok you can look into Views Field View (instructions on how to use it are in Readme file, you could create Embed display with your content and a term contextual filter, then embed it as the third field in the above Views), Views Aggregator Plus has more aggreagator options, Views Distinct (D7 only, might be used to create a new view with its "Aggregate Repeats" and then use regular Aggregation on it).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.