代码之家  ›  专栏  ›  技术社区  ›  anschauung

请检查是否白痴:在Drupal中自定义分类术语页

  •  2
  • anschauung  · 技术社区  · 15 年前

    我一直在尝试让我的Drupal6模块自定义分类术语页在特定条件下的显示方式。这很容易通过主题来完成,但似乎没有一种直接的方式通过模块来完成。

    经过大量的尝试、错误和谷歌搜索,我想出了以下方法来实现这一点:

    它似乎工作得很好,而且 感觉 比我在网上找到的其他解决方案更不黑客。但是,我担心的是,我在许多Drupal论坛页面上都没有看到这个例子——这让我觉得这个解决方案可能有一些可怕的错误,我还没有看到。

    有谁能看到这个解决方案的问题,或者(更好的)提出一个可以建立在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 回复  |  直到 15 年前
        1
  •  4
  •   John Fiala    15 年前

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

    否则,我将在模块上下文中这样做。

        2
  •  0
  •   arieltools    15 年前

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