You are here

Showing node count per term in views listing

Here are the step needed to show the count of nodes that are tagged with each term in a term list view!

  1. In your term list view, add a relationship (in the 'Advanced' section, which is collapsed by default) to the nodes tagged with that term.  In my example, my term is called 'Topic'
  2. When you are configuring this relationship, you have the choice to exclude terms that don't contain the relationship (so to exclude terms that have no nodes tagged with it) or not.  In my case, I want to display all terms, even if they have 0 nodes with that topic, so I will leave that box unchecked. I have also renamed this relationship to make it easier for me to reference in the future:
  3. Next, we want to enable aggregation in our view
  4. Finally we are ready to add node info along with each of the listed terms.  Go back to the 'Fields' section of your view and add a node field.  We won't actually display it, but will just use it for counting.  In my example, I'm choosing to add 'Node: nid' because that's unique.  After you add your field, it'll ask you what type of Aggregation you want, since we enabled aggregation for this view.  Choose 'Count DISTINCT'
  5. If you just leave the field like that, you'll see that it'll print out the count of the node nids for each of the taxonomy terms it has listed, but it won't be very pretty!  So, in the configuration screen for this field, I prefer to have the following settings.  Note that I am not including a label and am surrounding the field output with parentheses:
  6. Now your view output should be something like this:
  7. To make it even better, let's click to edit the Field Settings in the 'Format' section.  We can make these fields inline, so they appear in one line
  8. Now, this will be your final output




Very helpful post. thanks

Is there a way to also show (0) if you use filter criterias? I can't get it to work with them. If there is no node using a term, this term gets completely hidden.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.