<?phpfunction counter_count_nodes($tid, $type = 0, $status = 0) { static $count; if (!isset($count[$type]) || !isset($count[$status])) { // $type == 0 always evaluates TRUE if $type is a string if (is_numeric($type) || is_numeric($status)) { $result = db_query(db_rewrite_sql('SELECT t.tid, COUNT(n.nid) AS c FROM {term_node} t INNER JOIN {node} n ON t.nid = n.nid WHERE n.status = 1 GROUP BY t.tid')); } else { $result = db_query(db_rewrite_sql("SELECT t.tid, COUNT(n.nid) AS c FROM {term_node} t INNER JOIN {node} n ON t.nid = n.nid INNER JOIN {content_type_action} a ON a.nid = n.nid AND a.vid = n.vid WHERE n.status = 1 AND n.type = '%s' AND a.field_status_value = '%s' GROUP BY t.tid"), $type, $status); } while ($term = db_fetch_object($result)) { $count[$type][$status][$term->tid] = $term->c; } }// foreach (_taxonomy_term_children($tid) as $c) {// $children_count += taxonomy_term_count_nodes($c, $type);// } return $count[$type][$status][$tid] + $children_count;}