Anyone who's made a large image gallery with the Image Gallery module will be familiar with the following situation, you see, when you view an individual image, there are no links to the Previous and Next picture, so you have to navigate back to your Gallery to click the next thumbnail.

So, what can we do about that? Well, we can use Custom Pagers, Token and Views to add these links, that's what.

First you need to install the modules, use the following links to the projects:
http://drupal.org/project/custom_pagers
http://drupal.org/project/token
http://drupal.org/project/views

Custom Pagers allows you to add pagers to node types, in this case, image nodes, and it allows the use of php code & views to it's bidding, in this howto I'll be using the views functionality.

We start by creating a new view, so goto admin->views, and let's start with adding it.
The first thing we have to do is name our view, I'll call it "Image", and it's visible to all, you can also add a description if you like.

Next thing we have to configure is the Page of the view, we select "Provide a page view" and add an url for the view, i use 'pic', but you can use any available url you like, i set View type; Full nodes, and enabled "Use pager". It's important to note that this pager is NOT the pager provided by the Custom Pagers module, and it's not a required step to make this work. I also set Nodes per page to 1.

Now we go to the Fields section of the view, we need to add a field of the type "Image:Display image", and set the handler to "Image", you can also select the option to view a thumbnail, the original or a preview, i used a preview, but you can use any option you like.

Next up are the Arguments, We add an argument of the type "Taxomony: Term ID" and we set the default to "Display All Values".

We're almost through the view, so now we setup the filters applied to the view, we add a filter of the field "Node:Type", the operator to "Is one of" and the value to "Image".

Only one more thing to setup in the view, we goto setup the Sort Criteria, we add a field Node: Created time, Order to Ascending and Option to Normal.

You can now save the view, and test it by surfing to http://www.yoursite/pic you should see the very first Image node you created, if you don't, verify your settings (or import the view snippet below).

Now that we have our view, we can add our pager, so goto admin->custom pagers and add a new pager. I called mine Pictures, but again, feel free to change this name to whatever suits you. You also have to define where you want to position the pager, i added it above the image, so I selected "Above the node's body".

You need to select where the pager will be visible, you do that by choosing Image in the "By node type" list, we also need to specify the view with the "Use a view" dropdown menu, just select the view we just created. The last remaining thing to do is to specify the view arguments and sorting, fill in "[term-id]" and select the "Reverse the list of nodes", and click save.

Now, if you view an image, it should offer the "Previous" and "Next" links.

I'd like to thank setvik from #drupal-support to guide me through Custom pagers, without his help i'd probably still be cursing at my screen.

Views snippit:

  $view = new stdClass();
  $view->name = 'Image';
  $view->description = '';
  $view->access = array (
);
  $view->view_args_php = '';
  $view->page = TRUE;
  $view->page_title = '';
  $view->page_header = '';
  $view->page_header_format = '1';
  $view->page_footer = '';
  $view->page_footer_format = '1';
  $view->page_empty = '';
  $view->page_empty_format = '1';
  $view->page_type = 'node';
  $view->url = 'pic';
  $view->use_pager = TRUE;
  $view->nodes_per_page = '1';
  $view->sort = array (
    array (
      'tablename' => 'node',
      'field' => 'created',
      'sortorder' => 'ASC',
      'options' => 'normal',
    ),
  );
  $view->argument = array (
    array (
      'type' => 'taxid',
      'argdefault' => '2',
      'title' => '',
      'options' => '',
      'wildcard' => '',
      'wildcard_substitution' => '',
    ),
  );
  $view->field = array (
    array (
      'tablename' => 'image_node',
      'field' => 'nid',
      'label' => '',
      'handler' => 'image_views_handler_image_img',
      'options' => 'preview',
    ),
  );
  $view->filter = array (
    array (
      'tablename' => 'node',
      'field' => 'type',
      'operator' => 'OR',
      'options' => '',
      'value' => array (
  0 => 'image',
),
    ),
  );
  $view->exposed_filter = array (
  );
  $view->requires = array(node, image_node);
  $views[$view->name] = $view;

Comments

iantresman’s picture

See also under: Snippets » Module snippets: Views:
Add Back/Next Links to Nodes

No programming required.

jjjames’s picture

Can you do an update that works with Views2? I can't add fields after I select RowStyle: Node. Also, for some reason, Custom Pagers doesn't show a view created this way, so I can't select it from the list.
Thanks alot!

erantone’s picture

Go to custom_pagers.admin.inc inside the custom_pagers directory and edit, from line 130:

  if (module_exists('views')) {
    $options = array();

    $all_views = views_get_all_views();
    foreach ($all_views as $view) {
      // Only views that have fields will work for our purpose.
      //if (!empty($view->display['default']->display_options['fields']) && $view->base_table == 'node') {
        $options[$view->name] = $view->name;
      //}
    }

comment out the IF instruction as above. and that's it ! enjoy!

nimzie’s picture

I'm looking for this exact solution for D6. I have an existing gallery made with image gallery module.
Would need to retrofit code so that the node pages have previous and next links. Desperately trying to find this solution - and from reading around, there had been a bunch of patches proposed but I can't figure what is where ...
http://drupal.org/node/61704 is the discussion I found with the proposed patches. ..

asb’s picture

Much more is possible with Custom pagers; there are additional snippets on this handbook page.

Advanced setups do no only allow to display "previous" and "next" links, but also to show thumbnail images of the previous and next image in galleries, and much more!