Closed (fixed)
Project:
Views (for Drupal 7)
Version:
7.x-3.0
Component:
Views Data
Priority:
Normal
Category:
Support request
Assigned:
Issue tags:
Reporter:
Created:
13 Aug 2014 at 06:13 UTC
Updated:
23 Aug 2017 at 15:05 UTC
Jump to comment: Most recent
Comments
Comment #1
swetaranjan7@yahoo.in commented?>
?>
?>[SOLVED]
I added below code in template.php
function node_sibling($dir = 'next', $node, $next_node_text=NULL, $prepend_text=NULL, $append_text=NULL, $tid = FALSE){
if($tid){
$query = 'SELECT n.nid, n.title FROM {node} n INNER JOIN {taxonomy_index} tn ON n.nid=tn.nid WHERE '
. 'n.nid ' . ($dir == 'previous' ? '<' : '>') . ' :nid AND n.status=1 '
. 'AND tn.tid = :tid ORDER BY n.created ' . ($dir == 'previous' ? 'DESC' : 'ASC');
//use fetchObject to fetch a single row
$row = db_query($query, array(':nid' => $node->nid, ':tid' => $tid))->fetchObject();
}else{
$query = 'SELECT n.nid, n.title FROM {node} n WHERE '
. 'n.nid ' . ($dir == 'previous' ? '<' : '>') . ' :nid AND n.type = :type AND n.status=1 '
. 'ORDER BY n.nid ' . ($dir == 'previous' ? 'DESC' : 'ASC');
//use fetchObject to fetch a single row
$row = db_query($query, array(':nid' => $node->nid, ':type' => $node->type))->fetchObject();
}
if($row) {
$text = $next_node_text ? $next_node_text : $row->title;
return drupal_get_path_alias('node/'.$row->nid) ;
} else {
return FALSE;
}
}
It helped me in making next and previous node in content pages of nodes.
Then I called the function in my node.tpl.php
$Next = node_sibling('next',$node,NULL,NULL,NULL,FALSE);
$Previous = node_sibling('previous',$node,NULL,NULL,NULL,FALSE);
Comment #2
mustanggb commentedComment #3
renatog commentedComment #4
renatog commentedHi @swetaranjan7, how are you?
How nice that it worked.
Thank you very much for share your solution for this question.
Good Work.
Regards.