Display a list of node titles in a category with links to the full term

Last modified: October 5, 2006 - 14:01

Please note: These snippets are user submitted. Use at your own risk. For users who have setup Drupal using a database other than the default (MySQL), please note that the snippets may contain some database queries specific to MySQL.

<?php
/**
* Creates a list of category titles with a link to each category term.
* And the number of items in each term in brackets. (x)
*
* Category term title (x) and link to full term
* date of last update
*
*
* This works with drupal 4.6 and 4.5.
*
* If you improve this snippet please post a new comment below.
*
*/

$result = db_query("SELECT d.tid, d.name, MAX(n.created) AS updated, COUNT(*) AS count FROM {term_data} d INNER JOIN {term_node} USING (tid) INNER JOIN {node} n USING (nid) WHERE n.status = 1 GROUP BY d.tid, d.name ORDER BY updated DESC, d.name");
 
$items = array();
  while (
$category = db_fetch_object($result)) {
   
$items[] = l($category->name .' ('. $category->count .')', 'taxonomy/term/'. $category->tid) .'<br />'. t('%time ago', array('%time' => format_interval(time() - $category->updated)));
  }
print
theme('item_list', $items);
?>

 
 

Drupal is a registered trademark of Dries Buytaert.