--- taxonomy_menu.module.orig	Mon Oct 17 06:56:43 2005
+++ taxonomy_menu.module	Mon Oct 17 06:39:45 2005
@@ -66,7 +66,11 @@
  * Implementation of hook_settings().
  */
 function taxonomy_menu_settings() {
-  $form .= form_checkbox(t('Display descendants'), 'taxonomy_menu_display_descendants', 1, variable_get('taxonomy_menu_display_descendants', 1), t('If checked, then when a term is selected all nodes belonging to subterms are also displayed.'));
+  $form .= form_checkbox(t('Display descriptions'), 'taxonomy_menu_display_descriptions', 1, variable_get('taxonomy_menu_display_descriptions', 0), t("If checked, a term's description will be displayed at the top of the node listing page."));
+
+  $form .= form_checkbox(t('Display descendants'), 'taxonomy_menu_display_descendants', 1, variable_get('taxonomy_menu_display_descendants', 1), t("If checked, all nodes belonging to a selected term's subterms are also displayed."));
+
+  $form .= form_checkbox(t('Display child terms'), 'taxonomy_menu_display_child_terms', 1, variable_get('taxonomy_menu_display_child_terms', 0), t("If checked, the term or vocabulary's immediate child terms are also displayed."));
 
   $form .= form_checkbox(t('Display node immediately'), 'taxonomy_menu_display_node_immed', 1, variable_get('taxonomy_menu_display_node_immed', 1), t("If checked, display the node immediately and not the teaser if only one node is associated for the term."));
 
@@ -81,18 +85,32 @@
  * Page callback that renders a node listing for the selected term.
  */
 function taxonomy_menu_page() {
+  $descriptions = variable_get('taxonomy_menu_display_descriptions', 0);
+  $descendants = variable_get('taxonomy_menu_display_descendants', 1);
+  $child_terms = variable_get('taxonomy_menu_display_child_terms', 0);
+  $node_immediately = variable_get('taxonomy_menu_display_node_immed', 1);
+
   if (arg(2)) {
     $arguments = explode('/', $_GET['q']);
     $main_tid = db_escape_string(array_pop($arguments));
     
     drupal_set_html_head('<link rel="alternate" type="application/rss+xml" title="RSS" href="'. url('taxonomy/term/'. $main_tid .'/'. (variable_get('taxonomy_menu_display_descendants', 1) ? 'all' : 0) .'/feed') .'" />');
     
-    $result = taxonomy_select_nodes(array($main_tid), 'or', variable_get('taxonomy_menu_display_descendants', 1) ? 'all' : 0);
-  }
-  else {
+    $nodes = taxonomy_select_nodes(array($main_tid), 'or', variable_get('taxonomy_menu_display_descendants', 1) ? 'all' : 0);
+
+    if ($descriptions) {
+      $term = taxonomy_get_term($main_tid);
+      $description = '<div class="taxonomy_menu_description">' . $term->description . '</div>';
+    }
+
+    if ($child_terms) {
+      $terms_to_list = taxonomy_get_tree($vid, $main_tid, -1, 1);
+    }
+  } else {
     // If no arg(2), we're looking at just the vid. If display_descendants
     // is on, grab all terms regardless of depth. If off, grab depth 0 terms.
-    $tree = taxonomy_get_tree(arg(1));
+    $vid = arg(1);
+    $tree = taxonomy_get_tree($vid);
     $descendants = variable_get('taxonomy_menu_display_descendants', 1);
     foreach ($tree as $term) {
       if ($descendants || $term->depth == 0) {
@@ -100,12 +118,39 @@
       }
     }
     
-    // The requested terms have already been determined, so don't request
-    // descendants here.
-    $result = taxonomy_select_nodes($tids, 'or', 0);
+    if ($child_terms) {
+      $terms_to_list = taxonomy_get_tree($vid, 0, -1, 1);
+    } else {
+      // The requested terms have already been determined, so don't request
+      // descendants here.
+      $nodes = taxonomy_select_nodes($tids, 'or', 0);
+    }
+
+    if ($descriptions) {
+      $vocab = taxonomy_get_vocabulary($vid);
+      $description = '<div class="taxonomy_menu_description">' . $vocab->description . '</div>';
+    }
+
   }
   
-  print theme('page', taxonomy_render_nodes($result));
+  if ($terms_to_list) {
+    foreach ($terms_to_list as $term) {
+      $term_list_output .= theme('taxonomy_menu_term', $term);
+    }
+  }
+
+  $nr_of_nodes = db_num_rows($nodes);
+  if ( ( $nr_of_nodes == 1 ) && ( $node_immediately ) ) {
+    $node = db_fetch_object($nodes);
+    drupal_goto(url("node/".$node->nid));
+  }
+
+  $rendered_nodes = taxonomy_render_nodes($nodes);
+  if (!$nodes && $terms_to_list) {
+    $rendered_nodes = '';
+  }
+  
+  print theme('page', $description . $rendered_nodes . $term_list_output);
 }
 
 /**
@@ -136,6 +181,7 @@
               $path = $old_path .'/'. $term->tid;
               $old_depth = $term->depth;
               $old_path = $path;
+	      
               if (in_array($term->tid, array_keys(taxonomy_node_get_terms($node->nid)))) {
                 menu_set_location(array(array('path' => $path, 'title' => t($term->name)), array('path' => 'node/'. $node->nid, 'title' => $node->title)));
                 // Quit after the first match.
@@ -147,6 +193,13 @@
       }
       break;
   }
+}
+
+/**
+ * Theme hook for listing terms.
+ */
+function theme_taxonomy_menu_term($term) {
+  return '<h2 class="node-title">' . l($term->name, 'taxonomy_menu/' . $term->vid . '/' . $term->tid) . '</h2>' . $term->description;
 }
 
 ?>
