Last updated 26 August 2009. Created on 17 November 2007.
Edited by ronald_istos, add1sun. Log in to edit this page.

This combines the two pager methods described in Add a << first < previous next > last >> Pager to Image Nodes Within a Gallery.

It also adds:

* Support to let the user back to the current gallery.
* Can choose what vocabulary holds the galleries in case the image nodes have more than one vocabularies associated.

In template.php:

function custom_pager($current_nid, $class = NULL, $gallery_vocabulary_id) {
  $tid = reset(array_keys(taxonomy_node_get_terms_by_vocabulary($current_nid, $gallery_vocabulary_id)));
  $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;

  $output .= '<div class="'.$class.'">';

  if($x > 1) {
    $output .= l('&laquo; primera', 'node/'. $nodes[1]->nid, array('title' => check_plain($nodes[1]->title), 'class' => $class), NULL, NULL, FALSE, TRUE);
    $output .= l('&lsaquo; anterior', 'node/'. $nodes[$x-1]->nid, array('title' => check_plain($nodes[$x-1]->title), 'class' => $class), NULL, NULL, FALSE, TRUE);
  $output .= ' ['.$x .' de '. $i.'] ';
  if($x < $i) {
    $output .= l('siguiente &rsaquo;', 'node/'. $nodes[$x+1]->nid, array('title' => check_plain($nodes[$x+1]->title), 'class' => $class), NULL, NULL, FALSE, TRUE);
    $output .= l('ultima &raquo;', 'node/'. $nodes[$i]->nid, array('title' => check_plain($nodes[$i]->title), 'class' => $class), NULL, NULL, FALSE, TRUE);

  $output .= '</div>';

  // per posar boto de tornar a la galeria
  $output .= '<div class="volver">Volver a: ';
  $galeria = taxonomy_get_term($tid);
  $output .= l($galeria->name, taxonomy_term_path($galeria));
  $output .= '</div>';

  return $output;

In node-image.tpl.php:

 if ($page && $terms) {
      print custom_pager($node->nid, pager, 4); }

Where the third argument is the vocabulary ID containing the galleries, in my case 4. (The id of the "Image Gallery" vocabulary or whatever.) You must adjust your style.css properly.

Lluis Ribas

Looking for support? Visit the forums, or join #drupal-support in IRC.