2

我一直在尝试让我的 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);
    }
}
4

2 回答 2

4

使用hook_menu_alter()而不是怎么样hook_menu()?这样,您可以清楚地更改分类创建的菜单项,而不必担心模块权重以及最后添加的项目。

否则,这就是我在模块上下文中执行类似操作的方式。

于 2009-09-30T18:51:57.453 回答
0

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

于 2010-02-21T11:31:55.650 回答