Recenlty i wanted to add a next and previous link when a visitor reads the full node page ( the node.tpl.php actually e.g node/1 , node/2 etc ) , so the visitor would not have to go back to 'views-page' and click to another 'node link' and so on and so on . I've found the Previous/Next API at the drupal.org site [ http://drupal.org/project/prev_next ] but to be honest it's still in dev enviroment ( 26.04.2011 ) and i dont want to overload my drupal installation with more modules more database tables ( perhaps ! ) etc . . . I like to keep things light and 'clear' :) So after spending some hours in the google world and reading various posts from various websites / blogs etc i came up with a pretty decent solution . The original inspiring post can be found here [ http://gerardmcgarry.com/blog/displaying-a-previous-next-post-link-your… ] . Please notice that you must have an average knowledge of the drupal cms development area in order to accomplish this task otherwhise you should use the previous/next api drupal module .By using a solution like this could lead you to a standard procedure for feature requests like a previous next image module or blog or whatever . Plus this solution is a multilanguage solution since i'm using 2 different languages at my website [ http://skia.gr hellenic & english ] . You can check out a full working example here http://skia.gr/photography/9643 What do we need for a task like this ? First of all we must find the template.tpl.php file from our theme folder for example if you have installed/enabled the mycooltheme at sites/default/themes/mycooltheme you can browse inside your theme folder and find the template.tpl.php file ( please note that this is the correct way for installing a drupal theme inside your sites folder you create a themes folder and then you put your theme's folder inside the themes folder.You dont 'install' a theme inside the root/themes folder ). If your theme does not use one ( a template.tpl.php file ) just create a template.tpl.php with your editor ( i'm using notepad++ by the way ) . Why do we need a template.tpl.php file ? Good question , we are going to add a 'function' in the drupal's core functionallity but without harming the core . If something goes wrong at a feature update of the drupal's core for example or a theme's update we'll just edit our 'custom' function and keep rocking :) . So this is the code you need
" . l(t($row[title]),"node/".$row[nid], array(attributes => array('title'=> t($row[title])))) . "";
}
//This selects the next record and builds it into an HTML string as in the previous example
$result = db_query("SELECT nid, title FROM {node} WHERE nid > %d AND type = '%s' AND language='%s' AND status = 1 ORDER BY nid ASC LIMIT 1",$nid,$ntype,$lang);
while ($row = db_fetch_array($result)) {
//Finally, we wrap the output in a containing DIV element for themeing purposes
$outputstring .= "
Replace the 'mycooltheme' word with yours theme name e.g zeropoint [ a very very nice starter theme at http://drupal.org/project/zeropoint ] save the template.tpl.php . Go to sites/all/themes/mycooltheme find and open the node.tpl.php ( if there's no such file as node.tpl.php search for a node.tpl.php inside your drupal installation folder find it and just copy paste it to your mycooltheme folder. Open it with you favourite editor and add this line of code
nid,$node->type,$node->language);} ?>
where you think it's better for your theme . A good place should be just before the area . Dont use it inside the content's div area unless you know what you are doing . Why do we need the if condition statement you might ask?Oh , another good question :D . Well we use the if statement in order to make sure that our prev/next functionallity will be visible only for the full nodes and not for e.g the first page etc. the background images are the black arrows [http://skia.gr/photography/9643 ] plus this probably wont have the same effect at your custom theme . I'm using fusion + skinr for creating a website from scratch . For the styling i've used this css at [ skia.gr ] . Find you style.css or
mycooltheme.css or a .css file that does not start with ie*.css and copy paste the below css code .
.post-navigation {
border-bottom:1px dashed #ccc;
float: right;
font-size: 10px;
margin-bottom: 15px;
padding-bottom: 13px;
width: 100%;
}
.post-navigation a:hover{color:#369}
.prevpost {float:left;width:48%;text-align:left;
background:url(../images/prev.gif) center left no-repeat;
padding-left:15px;
}
.nextpost {float:right;width:48%; text-align:right;
background:url(../images/next.gif) center right no-repeat;
padding-right:15px;
}
Finally clear all caches refresh the page and go to your mycoolwebsite/node/12 or to a node path that exists at your site and see if it works :) . If it does not exist well what can you say at least you've tried ? :) . . . Ok i'm just joking just read and repeat the above steps untill it works :D p.s : If you want to add a prev/next functionallity for only a custom node-type full node view you could just use the right sql syntax inside the mycooltheme_function or just change the if statement inside the node.tpl.php file e.g
type == 'story') {software_prevnext($node->nid,$node->type,$node->language);} ?>
Or you could just create a type-node.tpl.php file by coping pasting and renaming the node.tpl.php according to your needs and then editing it by adding the if statement etc.for more please read http://drupal.org/node/17565