开发者

how to redirect node/%node to custom page in drupal

I want redi开发者_StackOverflow社区rect node/%node page of one content type to its related another content types node/%node page


Using hook_menu_alter(), alter the page callback for node/%node. In your page callback, check the type of the node to invoke node_page_view on the node or redirect to the referenced node.

MODULE_menu_alter(&$items) {
  $items['node/%node']['page callback'] = 'MODULE_node_page_view';
}

MODULE_node_page_view($node) {
  if ($node->type == MODULE_NODE_TYPE) {
    $referenced_node = MODULE_get_related_node($node);
    drupal_goto('node/'. $referenced_node->nid);
  }
  else {
    return node_page_view($node);
  }
}


The function to do a redirect is drupal_goto().

You can for example do that by implementing hook_init() in a custom module, check if the path is node/something, load the node and if it's type X, redirect.


This could also possibly be done by putting <?php drupal_goto($related_url); ?> in a node-yourcontenttype.tpl.php in your theme folder.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜