Exposed view to show category count
Liliplanet - January 24, 2008 - 15:54
Hi,
I've created taxonomy categories for continent, country and state. (and must say it's heavy when you go to taxonomy term/#) as obviously it loads all the terms to find the specific term/#).
Please, as every country does not have content (a user) for the term, is it possible to have the amount of content per term show in the dropdown list (exposed view)?
United States (4)
Algeria (0)
Italy (2)
Basically so users do not have to go through each term to find no content in that view.
or
is it perhaps possible that the dropdown only shows terms that have content? That would be fabulous!
Look forward to any reply and thank you.
Lilian

Directory module?
Maybe Directory module is the closest match to your need. It displays a page, not dropdown list.
just thinking out loud
just thinking out loud here... i'm not sure about how to accomplish this with views, but it's a pretty simple db query to find the category/term count -- something like:
SELECT COUNT(nid) FROM term_node WHERE tid='[term id]';could be used in a block, a theme file, etc...
Exposed views count
Thank you for your reply.
mmm .. I've tried in the header of the view/page, and presume it's in the right direction, but I want the count in the dropdown of exposed views.
<?php
$taxo_id_arr = array(99);
$taxo_id = join($taxo_id_arr, ',');
$list_no_per_term = 4; // Maximum number of posts to list per term
foreach ($taxo_id_arr as $taxo_single_id => $taxo_single_id_name) {
$query = "SELECT DISTINCT n.nid, n.title, n.created
FROM {node} n
INNER JOIN {term_node} tn ON n.nid = tn.nid
WHERE tn.tid IN ($taxo_single_id_name) AND n.status = 1
ORDER BY n.created DESC";
$sql = db_rewrite_sql($query);
$result = db_query_range(db_rewrite_sql($sql), 0, $list_no_per_term);
$items = array();
while ($anode = db_fetch_object($result)) {
$term_names = array();
# gather, into $term_names, all the terms because of which this node was selected:
foreach (taxonomy_node_get_terms($anode->nid) as $term) {
if (in_array($term->tid, $taxo_id_arr))
$term_names[] = $term->name;
}
$items[]= l($anode->title, "node/$anode->nid");
}
if(count($items)) {
echo '<strong>' . join($term_names, ', ') . '</strong><br />';
print theme('item_list',$items);
}
}
?>
Perhaps any other ideas please ..
All the best,
Lilian
Taxonomy category link with count of terms
Read about the Taxonews.module at http://drupal.org/node/34460. It might do what you need.
If not, view our page for http://heartwoodtmn.org/node/20 to see if it would work for you. Our web host is updating our server and the site is periodically going down. If you get a Server Not Found error message, try again in a few minutes.
I began using this page over a year ago. At that time, I was struggling to understand Drupal, so I know I either found a snippet or pieced it together from articles posted on Drupal. I apologize that I cannot give credit to the original developer.
Put the code in the Body of your content and check mark the Input Format as 'php'.
You can read how to create a Taxonomy drop down menu at http://drupal.org/node/91924#comment-209160. Maybe you could grab something from the code below to get the count and format the results using the other snippet.
<?php
$my_vid = 7; // change to your vocabulary id
$sql = "SELECT vid, name FROM {vocabulary} WHERE vid = %d ORDER BY name";
$vocabularies = db_query($sql, $my_vid);
$output = "";
while ($avoc = db_fetch_object($vocabularies))
{
$output .= "<li><strong>". check_plain($avoc->name) ."</strong></li>\n"
. getChildTerms(0, $avoc->vid);
}
print "<div class='taxonomy_tree'><p><ul>\n" . $output . "</ul></p></div>\n";
function getNodeCount($tid)
{
$sql = "SELECT COUNT(1) as num "
. "FROM {term_node} "
. "WHERE tid = $tid";
return ($acount = db_fetch_object(db_query($sql)))? $acount->num : 0;
}
function getChildTerms($parent, $vid)
{
$sql = "SELECT td.tid, td.vid, td.name "
. "FROM {term_data} td "
. " JOIN {term_hierarchy} th on th.tid = td.tid "
. "WHERE th.parent = $parent "
. " AND td.vid = $vid "
. "ORDER BY td.weight, td.name ";
$terms = db_query($sql);
$output = "";
while ($aterm = db_fetch_object($terms))
{
$output .= "<li>"
. "<a href='/taxonomy/term/$aterm->tid'>$aterm->name</a> ("
. getNodeCount($aterm->tid).")</li>\n"
. getChildTerms($aterm->tid, $vid);
}
return ($output != "")? "<ul>\n" . check_markup($output) ."</ul>\n" : "";
}
?>
Thank you Ashford for your
Thank you Ashford for your reply. I've actually got it sorted as a dropdown. Mooffie created this beautiful module and it works fabulously!
see: http://drupal.org/node/217979
Have a great day.
Lilian
nice... very nice
simple and light weight....
I'm not even a programmer and I had it up and ruuning ...bing...bang...booom
Thanks the counts add just what I needed