views:

437

answers:

2

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);
    }
}
+4  A: 

Hey there.

How about using hook_menu_alter() instead of hook_menu()? That way you can change the menu item that taxonomy creates in a clear way, without having to worry about module weights and which item gets added last.

Otherwise, that's how I would do something like that in a module context.

John Fiala
Oooh -- great point. Thanks!
anschauung
+1 - hook_menu_alter is the way to go for this.
Henrik Opel
A: 

Have a look at content.module or views.module to see how it is implemented there, if you have them installed.

arieltools

related questions