我一直在尝试让我的 Drupal 6 模块在特定条件下自定义分类术语页面的显示方式。这很容易通过主题来实现,但似乎没有一种直接的方法可以通过模块来实现。
经过大量的试验、错误和谷歌搜索,我想出了以下方法来实现这一点:
它似乎运作良好,并且感觉比我在网上找到的替代解决方案要少得多。但是,我担心我在许多 Drupal 论坛页面上的任何地方都没有看到这个例子——这让我觉得这个解决方案可能有一些我还没有看到的可怕错误。
任何 SO'er 都可以看到这个解决方案的问题,或者(更好地)建议一种可以建立在 Drupal 现有主题钩子上的方法吗?
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);
}
}