문제

What I want is pretty simple. I have registered a path

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;
}

When this menu item is triggered, I want to redirect (without changing the url) to a taxonomy page, of which the term is chosen in a function that runs when this function is called.

How can I do this (especcially without changing the url) ?

도움이 되었습니까?

해결책

You can't call taxonomy_term_page directly as your page callback as you'd need to provide a load function to load the term, which is just going to be too difficult with the setup you've got.

Instead, define your own page callback as an intermediary and just return the output from taxonomy_term_page directly:

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 ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top