Drupal Category Listing Module


I was feeling pretty dumb. I migrated my blog from Movable Type to Drupal back in December. One of the things I lost in the move was a category index. I couldn't find a good way to get Drupal to give me a basic listing of category terms in a given vocabulary.

Here is what I wanted:

  • List taxonomy terms in a given vocabulary
  • Displayed vocabulary hierarchies properly
  • Optionally displayed category descriptions and article counts
  • Linked the term name to taxonomy/term/(tid)
  • Displayed in a properly themed unordered list

These requirements are so basic and obvious, I thought the module that did them had to exist. I was feeling like a big dummy for not figuring out where it was—either in the Drupal core or among the large number of freely available taxonomy modules.

There was an Austin-area Drupal get-together this past weekend. I attended and took the opportunity to ask for help. I asked what module would do what I want. Nobody could recommend one. It turns out the module I want doesn't seem to exist.

So I wrote one. It's called category_listing. You can see it in operation at my new blog category index. You also can see a vocabulary listing as produced by the module—but it isn't that exciting on my site.

There is a current copy of the category_listing module attached to this article. If you give it a try, I'd be interested in your feedback.

category_listing Drupal module (tar.gz)2.06 KB


Comments have been closed for this entry.

drupal categories module..

hi chip,
i know exactly what you mean - i have been feeling exactly the same! i assumed that this should be something that is relatively simple but after searching high and low i was feeling pretty stupid.

i've only recently got started with drupal and have managed to find my way around, but the categories module has me stumped. it makes sense that it should use taxonimy, but it seems a bit odd that there isnt a categories module by default.

i had a look at your example and its running in the main content area - wouldnt it be more suited as a sidebar module (ie, easily accessible on all pages)?


Looks like yet another

Looks like yet another reason that I should make the move from WP to Drupal! Good stuff!

Can this module display

Can this module display categories in multiple columns? I can't seem to find one that does for v6.

No, in fact that's exactly

No, in fact that's exactly the opposite of what this module does. It's designed to use the standard template list formatting for displaying the categories. So however your template displays list items is how the categories will appear.

Great Module


Great module, it's exactly what I needed.

I've created a function that produces a list appropriate for a block that doesn't overwrite the page title, and assumes a vocabulary ID will be provided, so it's a slimmed down version of the page function.

function category_listing_block($vid) {

   * Retrieve configuration settings.
  $show_node_counts = variable_get('category_listing_enable_node_counts', TRUE);
  $show_descriptions = variable_get('category_listing_enable_descriptions', TRUTRUE);

   * Retrieve information on the requested vocabulary.
  $vocab = taxonomy_get_vocabulary($vid);
  if (! $vocab) {
    drupal_set_message(t("Vocabulary id \"%vid\" not found.", array("%vid" => $vid)));
    return "";

  if (!variable_get(_category_listing_vocabulary_enabled_key($vid), TRUE)) {
    return drupal_access_denied();

  $output = "";

  if (!empty($vocab->description) && $show_descriptions) {
    $output = "<p>" . check_plain($vocab->description) . "</p>\n";

   * Initialize list that will hold all the term entries, indexed by term id.
  $items_by_tid[0] = array(
    'tid' => NULL,
    'data' => '__ROOT__',
    'children' => array()

   * Walk the tree of terms in this vocabulary.
  $terms = taxonomy_get_tree($vid);
  foreach ($terms as $term) {

     * Format entry for this term in the listing.
    $data = l($term->name, "taxonomy/term/" . $term->tid);
    if ($show_node_counts) {
      $data .= ' (' . taxonomy_term_count_nodes($term->tid) . ')';
    if (!empty($term->description) && $show_descriptions) {
      $data .= ' - ' . check_plain($term->description);

     * Create a list item for this term.
    $items_by_tid[$term->tid] = array(
      'tid' => $term->tid,
      'data' => $data,
      'children' => array(),

     * Attach this list item to its parent(s).
    foreach ($term->parents as $parent_tid) {
      $items_by_tid[$parent_tid]['children'][] =& $items_by_tid[$term->tid];


  $output .= theme_item_list($items_by_tid[0]['children']);
  return $output;

possible mod?

would it be possible to make this module display the titles of the articles that are in each category as a nested list under the appropriate category, rather than displaying the number of posts in each category? I do not expect to have a large number of posts in each category that I have, and would be able to reduce the number of clicks before the visitor gets to see the article they're looking for, thanks.

for example:

category 1
post a
post b
post c

category 2
post d
post e

Code is Frozen

I don't anticipate adding this. I've moved to Drupal version 6 and am not using this module any longer. So the code is frozen.