2012-02-23 99 views
0

我有一个链接由一个特定作者在节点上。我所需要的是当我点击链接时,我想转到同一作者的下一个节点。我能想到的获取下一个节点/ Drupal 7

回答

1

一种方法是将其链接到菜单回调(即类型为MENU_CALLBACK菜单项)node-by-author-after/%node说,与低于设定的方法,它的页面回调:

/** 
    * Page callback that redirects the current user to the next node of the same 
    * type by the same author 
    * 
    * @param $prev 
    * Node entity that was previously visited 
    * 
    * @see hook_menu(). 
    */ 
    function [module]_next_node_by_author($prev) { 
    // Previous node is not valid 
    if (!$prev || !isset($prev->nid)) { 
     drupal_not_found(); 
     return; 
    } 

    $uid = &$prev->uid; 
    // User exists and is active 
    if ($account = user_load($uid) && $account->status) { 
     // Get next node (same type) of this user that I have access to 
     $next_nid = 
     db_select('node', 'n') 
      ->fields('n', array('nid')) 
      ->condition('n.uid', $account->uid) 
      ->condition('n.type', $prev->type) 
      ->condition('n.nid', $prev->nid, '>') 
      ->addTag('node_access') 
      ->orderBy('n.nid', 'ASC') 
      ->range(0, 1) 
      ->execute() 
      ->fetchField(); 
     if (!empty($next_nid) && is_numeric($next_nid) && ($next = node_load($next_nid))) { 
     $uri = node_uri($next); 
     drupal_goto($uri['path']); 
     return; 
     } 
     else { 
     drupal_set_message(t('There are no more @types by @name', array('@type' => $prev->type, '@name' => format_username($account))); 
     drupal_goto('<front>'); 
     return; 
     } 
    } 
    else { 
     // Go back to the previous node 
     drupal_set_message(t('The author of this @type is either not on @site or has been blocked', array('@type' => $prev->type, '@site' => variable_get('site_name', 'Drupal')))); 
     $uri = node_uri($prev); 
     drupal_goto($uri['path']); 
    } 
    } 
+0

你能让我知道如何让按钮点击运行此代码。我有两个按钮:一个用于前一个,另一个用于下一组文章。谢谢 – uzair 2012-02-29 06:58:34