0
votes

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

2

2 Answers

1
votes
  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

0
votes

Here is a simple method available for the same :

$tid = 'Enter tid number say 5';
$nids = taxonomy_select_nodes($tid, FALSE);
// count node here
$count = count($nids);
// you can load node content here
$nodes = node_load_multiple($nids);