首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取当前作者的下一个节点/文章- Drupal 7

获取当前作者的下一个节点/文章- Drupal 7
EN

Stack Overflow用户
提问于 2012-02-23 13:26:05
回答 1查看 426关注 0票数 0

我在一个节点上有一个链接,它是由特定的作者创建的。我所需要的只是当我点击链接时,我想转到同一个作者的下一个节点。

EN

回答 1

Stack Overflow用户

发布于 2012-02-24 13:39:12

我可以想到的一种方法是将其链接到菜单回调(即类型设置为MENU_CALLBACK的菜单项),例如,下面设置为node-by-author-after/%node的方法作为页面回调:

代码语言:javascript
复制
  /**
   * 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']);
    }
  }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9413967

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档