If I click on the link taxonomy/term/1 I get a linked list of all nodes tagged with term #1. Is there a similar link at the vocabulary level that will give me a linked list of all terms in that vocab?

For example, I have a vocabulary "Downloads" with terms "Reference Docs" (taxonomy/term/1), "Supplements" (taxonomy/term/2), and "Software Tools" (taxonomy/term/3). If I create a URL for taxonomy/term/3 I get a page will all the nodes tagged as "Software Tools." Well and good.

But what I'd like to create is a "landing page" for Downloads which gives me a page with all the terms in that vocabulary. Something like this (URLs in parenthesis):

Reference Docs (taxonomy/term/1)
Supplements (taxonomy/term/2)
Software Tools (taxonomy/term/3)

The nearest thing I can figure is creating a Downloads link like this: taxonomy/term/1,2,3

But that isn't really what I want because (1) it's not automated; I have to update the link if I add a new term and (2) it lists the actual nodes; I'd prefer just the terms.

I can't be the first bloke to ask about this, but I can't (for the life of me) find an answer in the handbook...any suggestions?

Cheers,

-Erin

Comments

i10neorg’s picture

Take a look at the Taxonomy Context module, The module also includes a context-sensitive menu block for each vocabulary (then you can render the block in a page).

jastraat’s picture

Check out http://drupal.org/node/128085. It describes how to list all the terms within a vocabulary in a block

nancydru’s picture

The snippet in that article works great for me! Thanks.

Care to take a shot at an author count?

Nancy W.
now running 5 sites on Drupal so far
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in Your Database

jastraat’s picture

Could you be a bit more specific as to what you're looking for?

nancydru’s picture

but thanks for asking.

  $sql = t('SELECT DISTINCT n.uid, u.name FROM node n ');
  $sql .= t('INNER JOIN users u ON u.uid=n.uid ');
  $sql .= t('WHERE n.type = "special" ORDER BY n.uid ASC ');
  $result = db_query($sql);
  $items = array();

  while ($x = db_fetch_object($result)) { /* loop through each row returned */
   $count = db_result(db_query("SELECT COUNT(nid) FROM node WHERE uid = " . $x->uid. ' AND type = "special" '));
   $items [] = l($x->name, "user/$x->uid") . " ($count)";
  }
  if ( count($items) ) {  print ('<div class="no-bullet">'.theme('item_list', $items)."</div></td>\n"); }

Nancy W.
now running 5 sites on Drupal so far
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in Your Database

mohammed76’s picture

hi.

below is a code snibbit that works for me. it prints all terms in vocabulary number 1. if this what you want to achieve then it's the simplest thing you could try.

<?php
$vocabulary_id = 1;
$result = db_query("SELECT d.tid, d.name FROM {term_data} d WHERE d.vid = $vocabulary_id GROUP BY d.tid, d.name ORDER BY d.name");
$items = array();
while ($category = db_fetch_object($result)) {
$items[] = l($category->name, 'taxonomy/term/'. $category->tid);
}
print theme('item_list', $items);
?>

Mohammed al-shar'

Nattiq Technologies

Mohammed al-shar'

The Explorer

cog.rusty’s picture

If your vocabulary is a hierarchy and the terms you want have the same parent, for example

Downloads (taxonomy/term/4)
--Reference Docs (taxonomy/term/1)
--Supplements (taxonomy/term/2)
--Software Tools (taxonomy/term/3)

Then you can use a "depth": taxonomy/term/4/all

Otherwise, if you want to list the nodes of a whole vocabulary you could try using the Views module for your taxonomy listings, which gives you a lot of flexibility.

esmale’s picture

Wow...Ask and you shall receive. :)

I'll do these for homework and see what works best.

Cheers for the prompt suggestions!

-Erin

JStarcher’s picture

If your vocabulary is setup in a hierarchy, you can use this code:

$vid = 5;  // Set the vid to the vocabulary id of the vocabulary you wish to list the terms from
$parent = 25; // Set the parent term id for when the vocabulary is setup in a hierarchy
$items = array();
$terms = taxonomy_get_tree($vid, $parent);
foreach ( $terms as $term ) { 
    $count = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term->tid)); 
    $items[] = l($term->name, "taxonomy/term/$term->tid") . " ($count)";
}
if ( count($items) ) {  print theme('item_list', $items);}

If you don't have it setup in a hierarchy then just remove the $parent line or use the code from above.

ica’s picture

aymerick came with a module to address this issue - imo it should go to the core of Drupal

http://drupal.org/project/taxonomy_forceall

quote from the module info;

By default, the 'all' parameter is never set by drupal core. This module solves this by simply implementing a hook_init() function that catch if requested page is taxonomy/term/x and transform it into taxonomy/term/x/all.

vitt84’s picture


$vocabulary_id = 1;
$result = db_query("SELECT d.tid, d.name , COUNT(abb.nid) num FROM {term_data} d LEFT OUTER JOIN {term_node} abb ON d.tid=abb.tid WHERE d.vid = $vocabulary_id GROUP BY d.tid, d.name ORDER BY d.name");
$items = array();
while ($category = db_fetch_object($result)) {
$items[] = l($category->name, 'taxonomy/term/'. $category->tid) . "  (" . $category->num . ")";
}
print theme('item_list', $items);

florianr’s picture

Hello!

If I use the php snipet to get the listing, could I some how manage to sort the output, depending on the node creation date (for example)?
So that the first term in the list would be the term with the newes content, and the last one would have the first created content?

wessex’s picture

Could anyone suggest how this code could be modified to exclude a particular node type?

I have a vocabulary that is shared between the 'book' and a custom 'report' node types. I'd like to list only the terms that have been used in books, but can't figure out how.

I guess in summary I'd like to display all terms in a vocabulary that have been applied to node type 'book'.

Any pointers gratefully received!

Cheers,

Tom

wessex’s picture

Thanks Nancy, I'll give them a try!

alamgir99’s picture

I had the same need. This module solved.

http://drupal.org/project/vocabulary_list_nodes

nancydru’s picture