Search code examples
drupaldrupal-7drupal-views

How to display number of nodes with current term?


I try to display my taxonomy terms through views, from my vocbulary

now it goes like this

  • term1 name
  • term1 img

I need to add count of all nodes with that term, and it will look like ->

  • term1 name
  • term1 img
  • count of all nodes with *term1*

so far, my idea was to display term id in additional field, after use preprocess function, and run SQL query to count all nodes with that term,

but i think there must be a easy way, looking for ideas


Solution

    1. Create Taxonomy Views.
    2. Add relationship to the node (in case if you want to count number of nodes).
    3. Enable grouping (Group by) (or "Use aggregation" toggle in D7, then set the "Aggregation Settings" for each field)
    4. In Style Settings/Format set Grouping field to 'Term ID' or 'Node ID' (depends of your query)
    5. Add new field 'Node: NID' and set Group type to: Count

    That should give you the count

    Ref : http://drupal.org/node/603868#comment-4421144