Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I wanted to output a custom html string with Previous/Next API ->
Here's the function I used in the template file to do it hope this helps someone create a cool node pager
<?php
function pn_node($node, $mode = 'n') {
if (!function_exists('prev_next_nid')) {
return NULL;
}
switch($mode) {
case 'p':
$n_nid = prev_next_nid($node->nid, 'prev');
$link_text = 'previous';
break;
case 'n':
$n_nid = prev_next_nid($node->nid, 'next');
$link_text = 'next';
break;
default:
return NULL;
}
if ($n_nid) {
$n_node = node_load($n_nid);
switch($n_node->type) {
case 'my_content_type':
if ($mode == 'p') {
return '<a href="node/' . $n_nid . '" class="prev"><span>' . $n_node->title .'</span></a>';
}
else {
return '<a href="node/' . $n_nid . '" class="next"><span>' . $n_node->title .'</span></a>';
}
}
}
}
?>
Comments
Comment #1
bhosmer CreditAttribution: bhosmer commentedThanks for sharing. You should add this to the Drupal Snippets