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.
Based on the original code in Add a << first < previous next > last >> Pager to Image Nodes Within a Gallery amended about localization.
- To file template.php add function:
/* Image Gallery Pager */
function custom_pager($current_nid, $class = NULL) {
$tid = reset(array_keys(taxonomy_node_get_terms($current_nid)));
$result = db_query(db_rewrite_sql('SELECT n.nid, n.title FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid = %s AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC, n.nid DESC'), $tid);
while ($node = db_fetch_object($result)) {
$nodes[++$i] = $node;
if ($node->nid == $current_nid) $x = $i;
}
if($x > 1) {
$output .= l(t('« first'), 'node/'. $nodes[1]->nid, array('title' => check_plain($nodes[1]->title), 'class' => $class), NULL, NULL, FALSE, TRUE);
$output .= l(t('‹ previous'), 'node/'. $nodes[$x-1]->nid, array('title' => check_plain($nodes[$x-1]->title), 'class' => $class), NULL, NULL, FALSE, TRUE);
}
else {
// not required
// $output .= '<span class="">' . t(t('« first')) . ' </span>' . '<span class="">' . t('‹ previous') . ' </span>';
}
$output .= $x .' ('. $i .')';
if($x < $i) {
$output .= l(t('next ›'), 'node/'. $nodes[$x+1]->nid, array('title' => check_plain($nodes[$x+1]->title), 'class' => $class), NULL, NULL, FALSE, TRUE);
$output .= l(t('last »'), 'node/'. $nodes[$i]->nid, array('title' => check_plain($nodes[$i]->title), 'class' => $class), NULL, NULL, FALSE, TRUE);
}
else {
// not required
// $output .= '<span class="">' . t(t('next ›')) . ' </span>' . '<span class="">' . t(t('last »')) . ' </span>';
}
return $output;
} - Add the following to node-image.tpl.php (a copy of node.tpl.php in your theme folder):
<!-- Image Gallery Pager -->
<div class="pager">
<?php if ($page != 0 && $terms) { print custom_pager($node->nid); } ?>
</div>