Hello.

I am look for a PHP Code to count the number of nodes assigned to a taxonomy term.

I just found the following code snippet: http://drupal.org/node/139934

Unfortunately this is for views but I need a normal PHP code which I could enter anywhere I would like.

Thanks in advance!

Regards Florian

Comments

Anonymous’s picture

Try using taxonomy_select_nodes http://api.drupal.org/api/function/taxonomy_select_nodes/5
You'll get all the nodes, then just count them using some php code.

Doug Gough
ImageX Media

WorldFallz’s picture

http://drupal.org/node/195034 might be closer to what you're looking for though the node counting method would also work.

===
"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." - Ben Franklin
"Search is your best friend." - Worldfallz

jclaussen’s picture

The site map can display the following items:

* Any categories, i.e vocabulary, with all the terms expanded. Optionally with node counts and RSS feeds.

http://drupal.org/project/site_map

wflorian’s picture

Thanks to all of you.

I think the following code would be the best:

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)

  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);
  }

Actually I am no PHP pro. How could I transform the code that it would fit my needs?

I have static page. On this page there are listed serveral taxonomy terms. Behind every term I want to post the nodecount. Means I don't need the PHP to be really dynamic. I would fill in the termid manually for every term...

Anybody any idea?

Thanks a lot again.

Regards.
Florian