I'm not sure what module or if I can do this with a module for 6.x that will display in a block a list of the terms in a vocabulary and the number of terms displayed next to the term. So...

Dogs (9)
Cats (3)
Birds (14)

etc..

Comments

WorldFallz’s picture

http://drupal.org/project/views

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

rkdeveloper’s picture

http://drupal.org/node/195034

with views it's not possible to show node count

make it simple will make your life easy........
Ram

WorldFallz’s picture

with views it's not possible to show node count

um... it most certainly is, they are called "summary" views. you really should know what you're talking about before stating something as a "fact".

For an example see: http://www.elderweb.com/home/sitemap/A

For 2 writeups see:

For d5 this is easily done with views + views_bonus (which includes the abc style view ready to enable).

In d6 core views2 includes a "glossary" style view that just needs to be enabled.

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

alan d.’s picture

Best to throw it in a module using hook_block, http://api.drupal.org/api/function/hook_block, but php code in a block would do:

<?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/>';
    // for each vocab 
    $terms_in_vocab_sample = db_query("SELECT * FROM {term_data} WHERE vid = %d ORDER BY name LIMIT 10", $vocab->vid);
    $items = array();
    while($r = db_fetch_object($terms_in_vocab_sample)) {
      $items[] = $r->name . ' is used by ' . taxonomy_term_count_nodes($r->tid) . ' nodes and has ' . count(taxonomy_get_children($r->tid)) . ' children terms.'; 
    }
    $output .= theme('item_list', $items);
  }
  
  print $output;
?>

This produces something like:

Sports

Total 10 terms:

  • Aid climbing is used by 0 nodes and has 0 children terms.
  • Bouldering is used by 1 nodes and has 0 children terms.
  • Climbing is used by 2 nodes and has 5 children terms.
  • Ice climbing is used by 0 nodes and has 0 children terms.
  • ...

PS: Not fully sure what you mean by number of terms displayed next to the term


Alan Davison
www.caignwebs.com.au

Alan Davison
alan d.’s picture

This is a much more expensive DB operation, rechecks each level for children and recursively does the same for their children:

<?php print taxonomy_get_tree($vocab->vid, $r->tid); ?>


Alan Davison
www.caignwebs.com.au

Alan Davison
chinafka’s picture

At least at that level and just linking me to the views module isn't really going to help me out.

Look at this site http://www.collegevolleyballcoach.com/

The way the terms on the right also have the term count next to them, that's all that I need.

WorldFallz’s picture

...and just linking me to the views module isn't really going to help me out.

wow, maybe it's just been a really bad week in the forums for these kinds of posts, but holy smokes that just strikes me so very wrong. In your original post you asked for a module recommendation (nothing more), and that's precisely what i gave you. It's also exactly doable with views. If you don't want to spend the time or effort necessary to learn views then you can use the code provided in another reply above.

If you expected or wanted a tutorial then you should have asked for one, you asked only for a module recommendation. We're a little light on ESP here-- it's very difficult provide answers to requests that have never been verbalized.

If you expect people in the forums to do what you want for you without having to do any homework then you're using the wrong cms.

and btw, had you simply typed "term count block" into the d.o. searchbox (or searched d.o. with google), you would have been greeted with a solution to your request in the very first page of results.

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

ntg’s picture

Thank you so much! That was what I was looking for. I modified it a bit though to match my requirements.

I needed a way to show the number of categories/terms in a specific vocabulary (vid=1) so I modified the code to this:

  $output = '';
    $term_count = db_result(db_query("SELECT count(*) FROM {term_data} WHERE vid = 1"));
    $output .= '<h4>' . $vocab->name . '</h4><p>Categories: ' . $term_count . '<br/>';
  print $output;

Hope it helps people who want to do something similar.