2011-12-01 30 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