我想要的很简单。我注册了一个路径
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) ?
你不能直接调用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);
}