请检查Idiocy:在Drupal中自定义分类术语页面

时间:2009-09-30 14:38:24

标签: drupal drupal-6 drupal-modules

我一直在努力让我的Drupal 6模块自定义分类术语页面在某些条件下显示的方式。这很容易通过主题来实现,但似乎没有一种通过模块实现这一目标的简单方法。

经过大量的试验,错误和谷歌搜索后,我想出了以下完成此任务的方法:

它似乎运行良好,感觉比我在网上找到的替代解决方案更少hacky。但是,我担心的是,我在许多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);
    }
}

2 个答案:

答案 0 :(得分:4)

如何使用hook_menu_alter()代替hook_menu()?这样,您可以更改分类法以明确方式创建的菜单项,而无需担心模块权重以及最后添加的项目。

否则,我会在模块上下文中做类似的事情。

答案 1 :(得分:0)

看一下content.module或views.module,了解它是如何在那里实现的。如果你已经安装了它们。

相关问题