[英]Drupal dynamic internal redirect
我想要的很簡單。 我已經注冊了一條路徑
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)?
您不能直接在page callback
調用taxonomy_term_page
,因為您需要提供一個加載功能來加載術語,而這對於您的設置來說太困難了。
而是將您自己的頁面回調定義為中介,然后直接從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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.