Taxonomies in Drupal provides an easy way to organize the content in Drupal. Usage of Taxonomies along with Views module makes Drupal as the most customizable content management system. We use Drupal for many of our customers and Views and Taxonomy are part of our regular installations.
In this Drupal tip, we are covering the creation of a taxonomy block with taxonomy names and number of nodes in each taxonomies.
1. Create a new view of taxonomy (Format type of your choice, I prefer unformatted list with Fields selected)
2. Add “Taxonomy term : Name” as the first field
3. Go to Relationships in the Advanced section and select “Taxonomy term: Content using your category”
4. Now you should enable the content aggregation so that we can modify the view to enable the counting of nodes
This will help you add additional fields in the field section.
5. Add “Content : Nid” in the fields section and “COUNT(DISTINCT Content: Nid)” settings in the aggregation section. This will eventually result in the counting of nodes in each taxonomy.
6. Once this step is completed, you need to display the fields in such a way that it is displayed properly. I often prefer to get this result in “Taxonomy Name (no)” form. This can be achieved by rewriting the results of the display. To achieve this, I have ordered the fields in the order of (1) Taxonomy Name (2) Content : NID and exclude “Taxonomy Name” from displaying.
Then Rewrite the results of “Content “ Nid” Field
This will result in displaying the Taxonomy names with the number of nodes in the taxonomy