Create a block with a list of categories and post count next to each, like in this example:
* Illustrator (35)
* InDesign (44)
* Photoshop (178)
* Quark XPress (4)

<?php
  if (user_access('access content')) {
    $result = db_query("SELECT term_data.tid, term_data.name, COUNT(*) AS count FROM {vocabulary_node_types} INNER JOIN  {term_data} USING (vid) INNER JOIN {term_node} USING (tid) INNER JOIN {node} USING (nid) WHERE node.status = 1 and vocabulary_node_types.type = 'blog' GROUP BY term_data.tid, term_data.name ORDER BY term_data.name");
    $items = array();
    while ($category = db_fetch_object($result)) {
      $items[] = l($category->name .' ('. $category->count .')', 'taxonomy/term/'. $category->tid);
    }

    return theme('item_list', $items);
  }
?>

Comments

barrandow’s picture

In Drupal 6 just retype "blog" to "story":
...vocabulary_node_types.type = 'story'...

chillz’s picture

It did not work in my case. I tested in in Drupal 6.12 and got the following error:

user warning: Unknown column 'term_data.tid' in 'field list' query: SELECT term_data.tid, term_data.name, COUNT(*) AS count FROM drupal_vocabulary_node_types INNER JOIN drupal_term_data USING (vid) INNER JOIN drupal_term_node USING (tid) INNER JOIN drupal_node USING (nid) WHERE node.status = 1 and vocabulary_node_types.type = 'story' GROUP BY term_data.tid, term_data.name ORDER BY term_data.name in C:\srv\apache\htdocs\drupal\includes\common.inc(1645) : eval()'d code on line 3.

Any idea why this is happening?

Daronna’s picture

Hi
I'm getting the same error as Chillz.
PHP is enabled
I have followed all the instructions and get the error.

Has anyone found a solution to this problem?
Is there a step I am missing?

I also tried it with "westwesterson's" code and get the same error.

Thanking anyone in advance
Daronna

westwesterson’s picture

This worked for me in drupal 6.13, make sure that you have php input filter enabled.

Also I tweaked this script slightly so that it would list terms by the count of taxonomy items. And limited to 25 terms.

  if (user_access('access content')) {
    $result = db_query("SELECT term_data.tid, term_data.name, COUNT(*) AS count FROM {vocabulary_node_types} INNER JOIN  {term_data} USING (vid) INNER JOIN {term_node} USING (tid) INNER JOIN {node} USING (nid) WHERE node.status = 1 and vocabulary_node_types.type = 'story' GROUP BY term_data.tid, term_data.name ORDER BY count desc LIMIT 25");
    $items = array();
    while ($category = db_fetch_object($result)) {
      $items[] = l($category->name .' ('. $category->count .')', 'taxonomy/term/'. $category->tid);
    }

    return theme('item_list', $items);
  }

Catagories should now show up as:
* Photoshop (178)
* InDesign (44)
* Illustrator (35)
* Quark XPress (4)

manoz_79’s picture

How can we also show the number of comments the term has in the nodes tagged with it.

espirates’s picture

There's a Taxonomy block module that does this perfectly

Sinan Erdem’s picture

It works nice for me on Drupal 6.14. But I was wondering instead of terms, can I show number of nodes in a whole vocabulary?

I mean instead of:
Austria(5)
Angola(2)
Australia(8)

I need:
Countries(15)

Sinan Erdem’s picture

I have just found a solution if anyone needs:

<?php

  $output = '';
  foreach(taxonomy_get_vocabularies() as $vocab) {
    $term_count = db_result(db_query("SELECT count(*) FROM {term_data} WHERE vid = %d", $vocab->vid));
    $output .= '<h4>' . $vocab->name . '</h4><p>Total ' . $term_count . ' terms.<br/>';
 
  print $output;
?>
ksteo’s picture

hello. I use the drupal 6.15 with easyphp 5.3 and also i have enable the php code. When i run the above code i get the message
Parse error: parse error in C:\Program Files\EasyPHP5.3.0\www\drupal\includes\common.inc(1685) : eval()'d code on line 3
Any help is wellcome
thanks

--Kostas--

Reager’s picture

Hi,
how can i limit the shown number of taxonomy to the last 24 hours