This simple block snippet displays a list of taxonomy terms without description in alphabetical order. Each term links to the corresponding term's edit form.

This is useful for example when you use the Taxonomy context module (http://drupal.org/project/taxonomy_context) and display descriptions of terms on the term listings pages.

<?php
/**
 * Creates a list of taxonomy terms without description in alphabetical order.
 * Each term links to the corresponding edit form.
 */
$query = "SELECT tid, name from {term_data} WHERE description = '' ORDER BY name ASC";
$result = db_query($query);
while ($term = db_fetch_object($result)) {
  $items[]= l($term->name, "admin/content/taxonomy/edit/term/$term->tid");
}
if(count($items)) {
  return theme('item_list',$items);
}
?>

Note: In Drupal 4.7 the URL in the l() function should be "admin/taxonomy/edit/term/$term->tid" instead.

Comments

avolve’s picture

I am using a slight modification of this snippet:

<?php
/**
* Creates a list of taxonomy terms without description in alphabetical order.
* Each term links to the corresponding taxonomy page.
*/
$query = "SELECT tid, name from {term_data} WHERE description = '' ORDER BY name ASC";
$result = db_query($query);
while ($term = db_fetch_object($result)) {
  $items[]= l($term->name, "taxonomy/term/$term->tid");
}
if(count($items)) {
  return theme('item_list',$items);
}
?>

It generates what i am after in a UL, though i have yet to work out how to generate the UL to have .first and .last classes (like other drupal generated lists). The aim is to improve CSS customisation.

Any one have a solution? I have tried to incorporate a call to the theme_links function, with no success.

avolve designs | ethical by design

amburi.roy’s picture

This code is very helpful to me. Thanks.