Blog post | by Boriana Ditcheva | Thu, May 09, 2013
Here are the step needed to show the count of nodes that are tagged with each term in a term list view!
- 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'
- 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:
- Next, we want to enable aggregation in our view
- 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'
- 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:
- Now your view output should be something like this:
- 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
- Now, this will be your final output