Wordpress like category menu

Wordpress like category menu in drupal 5, as shown below:

internet (5)
Google (1)
Yahoo (2)
Web 2.0 (1)
Misc (0)

<?php

$vid
= 4// Set the vid to the vocabulary id of the vocabulary you wish to list the terms from
$items = array();
$terms = taxonomy_get_tree($vid);
foreach (
$terms as $term ) {
   
$count = "<span>(".db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term->tid)).")</span>";
   
$items[] = l($term->name, "taxonomy/term/$term->tid") . " $count";
}
if (
count($items) ) {  print theme('item_list', $items);}
?>

Since I found the taxonomy_get_tree function returns the depth of each node, I modified the supplied code above like so:
Internet (18)
-- Mail (8)
-- Web (10)
Graphic (52)
-- Photoshop (50)
-- Corel (1)
-- Flash (1)
Security (8)
-- Firewall (2)
-- Anti virus (6)

<?php
$vid
= 4// Set the vid to the vocabulary id of the vocabulary you wish to list the terms from
$items = array();
$terms = taxonomy_get_tree($vid);
foreach (
$terms as $term )
{
 
$count = "(".db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term->tid)).")";
 
$termdepth = "";
  for (
$i=0;$i<$term->depth;$i++)
  {
   
$termdepth = $termdepth . "-- ";
  }
 
$items[] = $termdepth . l($term->name, "taxonomy/term/$term->tid") . " $count";
}
if (
count($items) ) {  print theme('item_list', $items);}
?>

Specifically, adding the inner for...loop to add the -- characters one time for each depth level. If you have too many levels and you don't want to return them all to this list, then call taxonomy_get_tree with the fourth parameter being the max depth.

Pretty cool, thank you

Lurple - July 2, 2008 - 14:37

I have a couple of questions-

1. Is there a simple way to skip counting revisions and just count the current version of a document?
2. Is there a simple way to just count things that are published and skip other things?

I have a fair amount of stuff queued up on my site for rolling out during times when I don't have the time to write something, and I don't want that data included in the count.

Thanks!
Lurple

 
 

Drupal is a registered trademark of Dries Buytaert.