Drupal-lovers

Who love to Drupal

Showing node count per term in views listing

Posted by drupallovers on July 28, 2014

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

Perfect!

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: