特定作者在节点上有链接。我需要的只是当我点击链接时,我想转到同一作者的下一个节点。
答案 0 :(得分: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']);
}
}