Simplified for just next/prev
I only needed next | prev so I simplified the code a bit and added append prepend text support. This goes to template.php. I also had do fix the first SQL query.
<?php
function next_prev($current_nid, $type, $button_type, $label, $prepend_text=NULL, $append_text=NULL) {
$tid = db_result(db_query(db_rewrite_sql("SELECT tid FROM {term_node} tn INNER JOIN {node} n ON tn.nid = n.nid WHERE tn.nid = $current_nid")));
switch ($button_type) {
case 'next':
$sort= 'DESC';
$case = '< ';
break;
case 'prev':
$sort = 'ASC';
$case = '> ';
break;
default:
return NULL;
break;
}
$sql = "SELECT n.nid, n.title FROM {node} n INNER JOIN {term_node} t ON n.nid = t.nid ";
$sql .= "INNER JOIN {term_data} r ON t.tid = r.tid WHERE n.type = '". $type ."' AND n.nid ". $case;
$sql .= $current_nid ." AND r.tid = ". $tid ." AND n.status = 1 ORDER BY nid ". $sort;
$result = db_fetch_array(db_query(db_rewrite_sql($sql)));
if (!$result) {
return NULL;
} else {
return $prepend_text.l($label, 'node/'. $result['nid'], array('title' => $result['title'])).$append_text;
}
}
?>In node.tpl.php I put this
<?php
if($page!=0&& $node->type=='image')
{
$previous_node_link = next_prev($node->nid, $node->type, 'prev', t('previous'), '<< ', NULL);
$next_node_link = next_prev($node->nid, $node->type, 'next', t('next'), NULL, ' >>');
print '<div class="previous-next-links">';
if($previous_node_link && $next_node_link)
{
print $previous_node_link.' | '.$next_node_link;
}
else if($previous_node_link)
{
print $previous_node_link;
}
else if($next_node_link)
{
print $next_node_link;
}
print '</div>';
}
?>