Community Documentation

Show a list of taxonomy terms without description

Last updated November 27, 2007. Created by yaph on October 8, 2006.
Edited by add1sun. Log in to edit this page.

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

I am using a slight

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.

This is great

This code is very helpful to me. Thanks.

Regards,
Amburi Roy.

About this page

Drupal version
Drupal 4.7.x, Drupal 5.x, Drupal 6.x

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here