2011-12-01 46 views
1

我想要的非常简单。我已经注册了一个路径Drupal动态内部重定向

function spotlight_menu() { 
    $items = array(); 

    $items['congres'] = array(
     'title' => 'Congres', 
     'title arguments' => array(2), 
     'page callback' => 'taxonomy_term_page', 
     'access callback' => TRUE, 
     'type' => MENU_NORMAL_ITEM, 
    ); 

    return $items; 
} 

当该菜单项被触发,我想重定向(不改变URL)的分类页面,其中选择在运行时调用该函数的功能术语。

我该怎么做(尤其是不改变url)?

回答

1

您不能直接调用taxonomy_term_page作为您的page callback,因为您需要提供加载函数来加载该术语,这对于您的设置来说太困难了。

取而代之的是,自己的网页回调作为中介,只是从taxonomy_term_page返回输出直接:

function spotlight_menu() { 
    $items = array(); 

    $items['congres'] = array(
    'title' => 'Congres', 
    'page callback' => 'spotlight_taxonomy_term_page', 
    'access callback' => TRUE, 
    'type' => MENU_NORMAL_ITEM, 
); 

    return $items; 
} 

function spotlight_taxonomy_term_page() { 
    // Get your term ID in whatever way you need 
    $term_id = my_function_to_get_term_id(); 

    // Load the term 
    $term = taxonomy_term_load($term_id); 

    // Make sure taxonomy_term_page() is available 
    module_load_include('inc', 'taxonomy', 'taxonomy.pages'); 

    // Return the page output normally provided at taxonomy/term/ID 
    return taxonomy_term_page($term); 
} 
+0

是啊,我用的是定制的回调,但它改为分类页面进行测试一些东西。无论如何,这工作就像一个魅力。 Thx非常! – Nealv