fix to loop through nodes so Prev/Next links are always there

fourtyonederful - February 20, 2009 - 19:13
Project:Custom Pagers
Version:6.x-1.10-beta1
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

When on the page 1 of 10, I wanted the Previous link to still appear, and send viewers to page 10 of 10, and same (or vice versa) for the Next, on page 10 of 10 to send users back to page 1 of 10.

In case anyone else is interested in this functionality, I changed the code around line 310 that was

  $vars['previous'] = !empty($nav['prev']) ? l(t('‹ previous'), 'node/'. $nav['prev']) : '';
  $vars['key'] = t('@count of @count_total', array('@count' => ($nav['current_index'] + 1), '@count_total' => count($nav['full_list'])));
  $vars['next'] =  !empty($nav['next']) ? l(t('next ›'), 'node/'. $nav['next']) : '';

to

  $vars['previous'] = !empty($nav['prev']) ? l(t('‹ previous'), 'node/'. $nav['prev']) : l(t('‹ previous'), 'node/'. $nav['last']);
  $vars['key'] = t('@count of @count_total', array('@count' => ($nav['current_index'] + 1), '@count_total' => count($nav['full_list'])));
  $vars['next'] =  !empty($nav['next']) ? l(t('next ›'), 'node/'. $nav['next']) : l(t('next ›'), 'node/'. $nav['first']);

and that did it. Seems like a nice thing to have.

#1

joachim - March 3, 2009 - 13:40

I've started a page of examples for this module: http://drupal.org/node/387786
Perhaps you'd like to add this to it?

 
 

Drupal is a registered trademark of Dries Buytaert.