From what I can tell, this is caused by a bug in the core function taxonomy_term_count_nodes (see this issue). Basically, if you have a hierarchal vocabulary, and a node is tagged with a term and at least one of its children (or just more than one of its children), that node gets counted once for each of the tags, and thus the function over counts. This bug can show up in the block provided by this module; it happens to be a fairly prominent error on my site.
Since it looks like the patch that issue isn't being ported to Drupal 6 anytime soon, I wrote a fix myself. Basically, I wrote a function to replace taxonomy_term_count_nodes. To use my fix, replace this, on line 617 of the module:
$count = taxonomy_term_count_nodes($term->tid);
with this:
$count = og_vocab_count_nodes($term);
Then, add this function to the bottom of the file:
<?php
function og_vocab_count_nodes($term) {
$children = taxonomy_get_children($term->tid, $term->vid);
$tids = array ($term->tid);
foreach ($children as $child) {
$tids[] = $child->tid;
}
$query = db_rewrite_sql('SELECT COUNT(n.nid) AS c FROM {term_node} t INNER JOIN {node} n ON t.nid = n.nid '.
'WHERE n.status = 1 AND t.tid IN(' . db_placeholders($tids, 'int') . ')');
$result = db_query($query, $tids);
$count = db_fetch_array($result);
return $count['c'];
}
?>
On a side note, the links in the block use the taxonomy_term view, which will only show nodes directly tagged with a term, and won't include child terms unless you set the view to have depth. In the attached screen shots and on my site, I updated the view to show nodes tagged with the main term or child terms down to a depth of 10 - on my site, that gets all of them.
The attached pictures show the before and after - each shows the nodes that have been tagged with term2 or one of its child terms (there are two such nodes). As you can see, before the patch the og_vocab block shows there being 5 such nodes, but after the patch it shows the correct number.
| Comment | File | Size | Author |
|---|---|---|---|
| after_patch.png | 36.21 KB | ensemble | |
| before_patch.png | 36.64 KB | ensemble |
Comments
Comment #1
ensemble commentedActually, I've now found some bugs in that method I wrote. It works on a simple test case, but not a more complex one. Consider the above code to be a possible jumping-off point if you want to fix it yourself; if I get it working correctly I'll post my fix.