I want to add some info to the taxonomy_term_page (path taxonomy/term/TID).

One simple solution is to add it directly inside the taxonomy_term_page() function but this makes it hard to maintain across updates of the taxonomy module etc.

So I would like a way to accomplish this from a separate module similar to what can be done to nodes with hook_nodeapi().

As a first atempt I tried this:

First i "override" the menu settings in my test.module

    $items[] = array('path' => 'taxonomy/term',
		     'title' => t('Taxonomy term'),
		     'callback' => 'test_term_page',
		     'access' => user_access('access content'),
		     'type' => MENU_CALLBACK
		     );

And in the callback i add my xtra info and calls the original taxonomy_term_page() function

function test_term_page() {
  $tid = arg(2);
  $result = db_query(db_rewrite_sql('SELECT description FROM {term_data} WHERE tid=%d'), $tid);;
  $data = db_fetch_object($result);
  $output =  '<div class="term-description">' . $data->description . '</div>';
  print theme('page', $output . taxonomy_term_page($tid));
}

If you don't want to affect all vocabularies I guess the module field of the vocabulary table togehter with taxonomy_term_path() function could be useful but I've not tried this.

Is there a simpler or more Drupalish way of accomplish this? Any suggestions welcome.

Comments

knugar’s picture

To handle multiple terms I changed the term_page() function:

function test_term_page() {
  $tids = arg(2);
  $terms = taxonomy_terms_parse_string($tids);

  if ($terms['tids']) {  
    $result = db_query(db_rewrite_sql('SELECT t.description FROM {term_data} t WHERE t.tid IN (%s)', 
				      't', 'tid'), 
		       implode(',', $terms['tids']));
    while ($term = db_fetch_object($result)) {
      $output .= $term->description . '<br/><br/>';
    }
    $output =  '<div class="term-description">' . $output . '</div>';
  }
  print theme('page', $output . taxonomy_term_page($tids));
}
davemybes’s picture

Take a look at http://drupal.org/project/taxonomy_context, it might be what you're looking for.
______________________________________________________________________________________________________
mybesinformatik.com - Drupal website development

______________________________________________________________________________________________________

knugar’s picture

I will have a look at the taxonomy_context module.