I've been trying to have my Drupal 6 module customize the way taxonomy term pages are displayed given certain conditions. This is easy to accomplish via themes, but there doesn't seem to be a straightforward way of accomplishing this via a module.
After a good deal of trial, error and Googling, I've come up with the following way of accomplishing this:
It seems to work well, and feels much less hacky than the alternate solutions I found online. But, I'm concerned at the fact that I didn't see this example anywhere on the many Drupal forum pages -- it makes me think that there might something horribly wrong with this solution that I haven't seen yet.
Can any SO'er see problems with this solution, or (better) suggest a method that could build on Drupal's existing theme hooks?
function foo_menu() {
// other menu callbacks ...
$items['taxonomy/term/%'] = array(
'title' => 'Taxonomy term',
// override taxonomy_term_page
'page callback' => 'foo_term_page',
'page arguments' => array(2),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
// other menu callbacks
}
function foo_term_page($str_tids = '', $depth = 0, $op = 'page') {
if ($my_conditions_are_true) {
// foo_theme_that_page is a copy-paste of taxonomy_term_page
// that includes the customizations I want
return foo_theme_that_page($str_tids,$depth,$op);
} else { //Conditions aren't met. Display term normally
module_load_include('inc', 'taxonomy', 'taxonomy.pages');
return taxonomy_term_page($str_tids,$depth,$op);
}
}