function theme_pager

You are here

7 pager.inc theme_pager($variables)
4.6 pager.inc theme_pager($tags = array(), $limit = 10, $element = 0, $attributes = array())
4.7 pager.inc theme_pager($tags = array(), $limit = 10, $element = 0, $parameters = array())
5 pager.inc theme_pager($tags = array(), $limit = 10, $element = 0, $parameters = array())
6 pager.inc theme_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 9)

Returns HTML for a query pager.

Menu callbacks that display paged query results should call theme('pager') to retrieve a pager control so that users can view other results. Format a list of nearby pages with additional query results.

Parameters

$tags: An array of labels for the controls in the pager.

$limit: The number of query results to display per page.

$element: An optional integer to distinguish between multiple pagers on one page.

$parameters: An associative array of query string parameters to append to the pager links.

$quantity: The number of pages in the list.

Return value

An HTML string that generates the query pager.

Related topics

27 theme calls to theme_pager()
blog_page_last in modules/blog/blog.pages.inc
Menu callback; displays a Drupal page containing recent blog entries of all users.
blog_page_user in modules/blog/blog.pages.inc
Menu callback; displays a Drupal page containing recent blog entries of a given user.
comment_admin_overview in modules/comment/comment.admin.inc
Form builder; Builds the comment overview form for the admin.
comment_render in modules/comment/comment.module
Renders comment(s).
dblog_overview in modules/dblog/dblog.admin.inc
Menu callback; displays a listing of log messages.

... See full list

File

includes/pager.inc, line 114
Functions to aid in presenting database results as a set of pages.

Code

function theme_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 9) {
  global $pager_page_array, $pager_total;

  // Calculate various markers within this pager piece:
  // Middle is used to "center" pages around the current page.
  $pager_middle = ceil($quantity / 2);
  // current is the page we are currently paged to
  $pager_current = $pager_page_array[$element] + 1;
  // first is the first page listed by this pager piece (re quantity)
  $pager_first = $pager_current - $pager_middle + 1;
  // last is the last page listed by this pager piece (re quantity)
  $pager_last = $pager_current + $quantity - $pager_middle;
  // max is the maximum page number
  $pager_max = $pager_total[$element];
  // End of marker calculations.

  // Prepare for generation loop.
  $i = $pager_first;
  if ($pager_last > $pager_max) {
    // Adjust "center" if at end of query.
    $i = $i + ($pager_max - $pager_last);
    $pager_last = $pager_max;
  }
  if ($i <= 0) {
    // Adjust "center" if at start of query.
    $pager_last = $pager_last + (1 - $i);
    $i = 1;
  }
  // End of generation loop preparation.

  $li_first = theme('pager_first', (isset($tags[0]) ? $tags[0] : t('« first')), $limit, $element, $parameters);
  $li_previous = theme('pager_previous', (isset($tags[1]) ? $tags[1] : t('‹ previous')), $limit, $element, 1, $parameters);
  $li_next = theme('pager_next', (isset($tags[3]) ? $tags[3] : t('next ›')), $limit, $element, 1, $parameters);
  $li_last = theme('pager_last', (isset($tags[4]) ? $tags[4] : t('last »')), $limit, $element, $parameters);

  if ($pager_total[$element] > 1) {
    if ($li_first) {
      $items[] = array(
        'class' => 'pager-first',
        'data' => $li_first,
      );
    }
    if ($li_previous) {
      $items[] = array(
        'class' => 'pager-previous',
        'data' => $li_previous,
      );
    }

    // When there is more than one page, create the pager list.
    if ($i != $pager_max) {
      if ($i > 1) {
        $items[] = array(
          'class' => 'pager-ellipsis',
          'data' => '…',
        );
      }
      // Now generate the actual pager piece.
      for (; $i <= $pager_last && $i <= $pager_max; $i++) {
        if ($i < $pager_current) {
          $items[] = array(
            'class' => 'pager-item',
            'data' => theme('pager_previous', $i, $limit, $element, ($pager_current - $i), $parameters),
          );
        }
        if ($i == $pager_current) {
          $items[] = array(
            'class' => 'pager-current',
            'data' => $i,
          );
        }
        if ($i > $pager_current) {
          $items[] = array(
            'class' => 'pager-item',
            'data' => theme('pager_next', $i, $limit, $element, ($i - $pager_current), $parameters),
          );
        }
      }
      if ($i < $pager_max) {
        $items[] = array(
          'class' => 'pager-ellipsis',
          'data' => '…',
        );
      }
    }
    // End generation.
    if ($li_next) {
      $items[] = array(
        'class' => 'pager-next',
        'data' => $li_next,
      );
    }
    if ($li_last) {
      $items[] = array(
        'class' => 'pager-last',
        'data' => $li_last,
      );
    }
    return theme('item_list', $items, NULL, 'ul', array('class' => 'pager'));
  }
}

Comments

If you want a pager in the style of the Deviantart site were 'first'&'last' links are hidden and the ellipsis are attached to the prev/next page numbers like so:
< prev ...3 4 5 6 7... next >

This put this code in your theme template.php file and rename the function to match your own theme name.

function yourthemename_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 5) {
  global $pager_page_array, $pager_total;
  $tags = array("", "< prev", "", "next >", "");

  // Calculate various markers within this pager piece:
  // Middle is used to "center" pages around the current page.
  $pager_middle = ceil($quantity / 2);
  // current is the page we are currently paged to
  $pager_current = $pager_page_array[$element] + 1;
  // first is the first page listed by this pager piece (re quantity)
  $pager_first = $pager_current - $pager_middle + 1;
  // last is the last page listed by this pager piece (re quantity)
  $pager_last = $pager_current + $quantity - $pager_middle;
  // max is the maximum page number
  $pager_max = $pager_total[$element];
  // End of marker calculations.

  // Prepare for generation loop.
  $i = $pager_first;
  if ($pager_last > $pager_max) {
    // Adjust "center" if at end of query.
    $i = $i + ($pager_max - $pager_last);
    $pager_last = $pager_max;
  }
  if ($i <= 0) {
    // Adjust "center" if at start of query.
    $pager_last = $pager_last + (1 - $i);
    $i = 1;
  }
  // End of generation loop preparation.

  $li_previous = theme('pager_previous', (isset($tags[1]) ? $tags[1] : t('‹ previous')), $limit, $element, 1, $parameters);
  $li_next = theme('pager_next', (isset($tags[3]) ? $tags[3] : t('next ›')), $limit, $element, 1, $parameters);

  if ($pager_total[$element] > 1) {

    if ($li_previous) {
      $items[] = array(
        'class' => 'pager-previous',
        'data' => $li_previous,
      );
    }

    // When there is more than one page, create the pager list.
    if ($i != $pager_max) {
      // Now generate the actual pager piece.
      for (; $i <= $pager_last && $i <= $pager_max; $i++) {
        if ($i < $pager_current) {
      if ($pager_first > 1 && $i == $pager_first) {
  $output = '...'.$i;
  $stopPreEllipsis = true;
  } else {
  $output = $i;
  }
          $items[] = array(
            'class' => 'pager-item',
            'data' => theme('pager_previous', $output, $limit, $element, ($pager_current - $i), $parameters),
          );
        }
        if ($i == $pager_current) {
          $items[] = array(
            'class' => 'pager-current',
            'data' => $i,
          );
        }
        if ($i > $pager_current) {

      if ($pager_last < $pager_max && $i == $pager_last) {
  $output = $i.'...';
  } else {
  $output = $i;
  }

          $items[] = array(
            'class' => 'pager-item',
            'data' => theme('pager_next', $output, $limit, $element, ($i - $pager_current), $parameters),
          );
        }
      }
    }
    // End generation.
    if ($li_next) {
      $items[] = array(
        'class' => 'pager-next',
        'data' => $li_next,
      );
    }

    return theme('item_list', $items, NULL, 'ul', array('class' => 'pager'));
  }
}

When the pager gets close to the last page, the marker "..." is added incorrectly:
«prev 5 ...6 7 [8] 9

Hi,
while i am adding this code in my basic theme template.I am getting following error.
Cannot unset string offsets in D:\Install\xampp\htdocs\myproject\sites\all\modules\devel_themer\devel_themer.module
how can i fix this error ?

I think you should set $pager_first back to $i after

// Prepare for generation loop.
  $i = $pager_first;
  if ($pager_last > $pager_max) {
    // Adjust "center" if at end of query.
    $i = $i + ($pager_max - $pager_last);
    $pager_last = $pager_max;

//should add
    $pager_first = $i;

That may cause "..." being added incorrectly when comes to the last pages of the pager

For an iStock photo style of pager, put this code in your template.php file:

It looks similar to

« ‹ … 3 | 4 | 5 | 6 | 7 of 21 › »

function yourthemename_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 5) {
  global $pager_page_array, $pager_total;

  // Calculate various markers within this pager piece:
  // Middle is used to "center" pages around the current page.
  $pager_middle = ceil($quantity / 2);
  // current is the page we are currently paged to
  $pager_current = $pager_page_array[$element] + 1;
  // first is the first page listed by this pager piece (re quantity)
  $pager_first = $pager_current - $pager_middle + 1;
  // last is the last page listed by this pager piece (re quantity)
  $pager_last = $pager_current + $quantity - $pager_middle;
  // max is the maximum page number
  $pager_max = $pager_total[$element];
  // End of marker calculations.

  $pager_delim = ' |';

  // Prepare for generation loop.
  $i = $pager_first;
  if ($pager_last > $pager_max) {
    // Adjust "center" if at end of query.
    $i = $i + ($pager_max - $pager_last);
    $pager_last = $pager_max;
  }
  if ($i <= 0) {
    // Adjust "center" if at start of query.
    $pager_last = $pager_last + (1 - $i);
    $i = 1;
  }
  // End of generation loop preparation.

  $li_first = theme('pager_first', (isset($tags[0]) ? $tags[0] : t('« ')), $limit, $element, $parameters);
  $li_previous = theme('pager_previous', (isset($tags[1]) ? $tags[1] : t('â¹ ')), $limit, $element, 1, $parameters);
  $li_next = theme('pager_next', (isset($tags[3]) ? $tags[3] : t('âº')), $limit, $element, 1, $parameters);
  $li_last = theme('pager_last', (isset($tags[4]) ? $tags[4] : t('»')), $limit, $element, $parameters);

  if ($pager_total[$element] > 1) {
    if ($li_first) {
      $items[] = array(
        'class' => 'pager-first',
        'data' => $li_first,
      );
    }
    if ($li_previous) {
      $items[] = array(
        'class' => 'pager-previous',
        'data' => $li_previous,
      );
    }

    // When there is more than one page, create the pager list.
    if ($i != $pager_max) {
      if ($i > 1) {
        $items[] = array(
          'class' => 'pager-ellipsis',
          'data' => 'â¦',
        );
      }
      // Now generate the actual pager piece.
      for (; $i <= $pager_last && $i <= $pager_max; $i++) {
        if ($i < $pager_current) {
          $items[] = array(
            'class' => 'pager-item',
            'data' => theme('pager_previous', $i, $limit, $element, ($pager_current - $i), $parameters).$pager_delim,
          );
        }
        if ($i == $pager_current) {
          $items[] = array(
            'class' => 'pager-current',
            /*'data' => '['.$i.']'.$pager_delim,*/
            'data' => $i,
          );
        }
        if ($i > $pager_current) {
          $items[] = array(
            'class' => 'pager-item',
            'data' => $pager_delim.theme('pager_next', $i, $limit, $element, ($i - $pager_current), $parameters),
          );
        }
      }
      if ($i < $pager_max) {
        $items[] = array(
          'class' => 'pager-ellipsis',
          'data' => 'of '.$pager_max,
        );
      }
    }
    // End generation.
    if ($li_next) {
      $items[] = array(
        'class' => 'pager-next',
        'data' => $li_next,
      );
    }
    if ($li_last) {
      $items[] = array(
        'class' => 'pager-last',
        'data' => $li_last,
      );
    }
    return theme('item_list', $items, NULL, 'ul', array('class' => 'pager'));
  }
}

I used the following CSS as well:

/* Make pagers right-justified */
div.item-list .pager {
  text-align: right;
}

div.item-list ul.pager li {
  margin: 0px;
  font-size : 0.8em;
  padding:2px;
}

div.item-list ul.pager li.pager-first,
div.item-list ul.pager li.pager-previous,
div.item-list ul.pager li.pager-next,
div.item-list ul.pager li.pager-last {
  background-image:url('images/pager_box.png');
  background-position: 0px 4px;
  padding:0.5em;
}
div.item-list ul.pager li.pager-first:hover,
div.item-list ul.pager li.pager-previous:hover,
div.item-list ul.pager li.pager-next:hover,
div.item-list ul.pager li.pager-last:hover {
  background-image:url('images/pager_box.png');
  background-position: 0px -16px;
  padding:0.5em;
}

pager_box.png files are just boxes that fit around the « and ‹ . Make an image 15 x 35 with two vertically stacked boxes: a 15x15 empty box at 0,0 and a 15x15 shaded box at 0,20.

Hi,

Thank you for this code.

I have copied this code in my template.php, but somehow in place of links and arrows for next/prev/page numbers it is printing the text 'Array'. I am using Drupal 6.

Can you please let me know what could be the cause.

Thank you,
Jay Mehta.

for line 91 change

if ($i < $pager_max) {

to

if ($i <= $pager_max) {

To have a pager in the following format.

Showing 1-50 of 53 next 3 ›

<?php
function themename_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 9){
    global
$pager_page_array, $pager_total, $pager_total_items;
   
   
$page = $pager_page_array[0] + 1;
   
$first_no = $limit * $pager_page_array[0] + 1;
   
$last_no = ($limit * $page) > $pager_total_items[0] ? $pager_total_items[0] : $limit * $page;
   
$next_no = $pager_total_items[0] - ($page * $limit) > $limit ? 50 : $pager_total_items[0] - ($page * $limit);
   
$previous_no = $limit;

   

$li_text = 'Showing '.$first_no.'-'.$last_no.' of '. $pager_total_items[0];
   
$li_previous = theme('pager_previous', t('‹ previous @no',array('@no'=>$previous_no)), $limit, $element, 1, $parameters);
   
$li_next = theme('pager_next', t('next @no ›',array('@no'=>$next_no)), $limit, $element, 1, $parameters);

    if (

$li_previous) {
   
$items[] = array(
     
'class' => 'pager-previous',
     
'data' => $li_previous,
    );
  }
  if (
$li_text) {
   
$items[] = array(
     
'class' => 'pager-text',
     
'data' => $li_text,
    );
  }
   
  if (
$li_next) {
   
$items[] = array(
     
'class' => 'pager-next',
     
'data' => $li_next,
    );
  }

  return

theme('item_list', $items, NULL, 'ul', array('class' => 'pager'));
 
}
?>

You hardcoded the number 50 in this line:

$next_no = $pager_total_items[0] - ($page * $limit) > $limit ? 50 : $pager_total_items[0] - ($page * $limit);

This makes no sense for me, instead i'll suggest the following:

$next_no = $pager_total_items[0] - ($page * $limit) > $limit ? $limit : $pager_total_items[0] - ($page * $limit);

So the function displays not a hardcoded number, though the limit or if less than the limit the lasting ones.

$pager_total_items[0] should be $pager_total_items[$element]

I have taken your wonderful pager a step further and added a "<< first" and "last >>", which my team wanted. Here it is:

<?php
/**
* Implementation of HOOK_pager().
*/

function [themename]_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 9){
    global
$pager_page_array, $pager_total, $pager_total_items;
   
   
$page = $pager_page_array[0] + 1;
   
$first_no = $limit * $pager_page_array[0] + 1;
   
$last_no = ($limit * $page) > $pager_total_items[0] ? $pager_total_items[0] : $limit * $page;
   
$next_no = $pager_total_items[0] - ($page * $limit) > $limit ? $limit : $pager_total_items[0] - ($page * $limit);
   
$previous_no = $limit;

   

$li_first = theme('pager_first', t('‹‹ first',array('@no'=>$previous_no)), $limit, $element, $parameters);
   
$li_text = 'Showing '.$first_no.'-'.$last_no.' of '. $pager_total_items[0];
   
$li_previous = theme('pager_previous', t('‹ previous @no',array('@no'=>$previous_no)), $limit, $element, 1, $parameters);
   
$li_next = theme('pager_next', t('next @no ›',array('@no'=>$next_no)), $limit, $element, 1, $parameters);
   
$li_last = theme('pager_last', t('last ››',array('@no'=>$pager_total)), $limit, $element, $parameters);

    if (

$li_first) {
     
$items[] = array(
       
'class' => 'pager-first',
       
'data' => $li_first,
      );
    }
   
    if (
$li_previous) {
   
$items[] = array(
     
'class' => 'pager-previous',
     
'data' => $li_previous,
    );
  }
  if (
$li_text) {
   
$items[] = array(
     
'class' => 'pager-text',
     
'data' => $li_text,
    );
  }
   
  if (
$li_next) {
   
$items[] = array(
     
'class' => 'pager-next',
     
'data' => $li_next,
    );
  }
 
  if (
$li_last) {
     
$items[] = array(
       
'class' => 'pager-last',
       
'data' => $li_last,
      );
    }

  return

theme('item_list', $items, NULL, 'ul', array('class' => 'pager'));
 
}
?>

Edit: You may also need the code below if you are using ApacheSolr on your site. I corrected the text in the pager. The core Search module had set a variable that we no longer use, and the variable value was 10 when we currently are using 20. The variable is now dynamic, so if we choose to show more search results per page then the pager text will reflect that. I have the ApacheSolr running on my site.

<?php
/**
* Process variables for search-results.tpl.php.
*
* The $variables array contains the following arguments:
* - $results
* - $type
*
* @see search-results.tpl.php
*/
function [themename]_preprocess_search_results(&$variables) {
 
$variables['pager'] = theme('pager', NULL, variable_get('apachesolr_rows', 20), 0);
}
?>

For D6:

To use theme_pager with your own custom query, you must use pager_query as it sets globals that theme_pager will use.

// Function to get comments via pager_query

function _myexample_comments($node_nid) {
  $sql = "SELECT n.nid FROM {node} n
          LEFT JOIN {content_type_mycontent_type} mc
          ON mc.nid = n.nid
          WHERE mc.field_custom_nid = %d
          AND n.status = 1
          ORDER BY n.created DESC";
  $result = pager_query($sql, 10, 0, NULL, array($node_nid));
  while($records = db_result($result)) {
    $comments[] = $records;
  }
 
  return $comments;
}

// Custom function to theme above results

function theme_myexample_comments_pager() {
  return theme('pager');
}

Or, set those globals yourself:

<?php
global $pager_page_array, $pager_total;

$page = isset($_GET['page']) ? check_plain($_GET['page']) : 0;
$pager_page_array = explode(',', $page);
$pager_total = array(ceil($num_results / $items_per_page));
?>

If you want it to behave just like most Wordpress pagers, showing only previous and next links, this short theme_pager override will do. It is a cleaned up version of theme_pager:

<?php
function yourtheme_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 9) {
  global
$pager_total;

 

$li_previous = theme('pager_previous', (isset($tags[1]) ? $tags[1] : t('‹ previous')), $limit, $element, 1, $parameters);
 
$li_next = theme('pager_next', (isset($tags[3]) ? $tags[3] : t('next ›')), $limit, $element, 1, $parameters);

  if (

$pager_total[$element] > 1) {

    if (

$li_previous) {
     
$items[] = array(
       
'class' => 'pager-previous',
       
'data' => $li_previous,
      );
    }

   

// End generation.
   
if ($li_next) {
     
$items[] = array(
       
'class' => 'pager-next',
       
'data' => $li_next,
      );
    }
    return
theme('item_list', $items, NULL, 'ul', array('class' => 'pager'));
  }
}
?>

To make an easy-to-use pager, put this in your template.php, and you will get something like:

« first ‹ previous ... 3 4 5 6 7 ... 14 next › last »

Make sure to change YOURTHEME to correct name.

<?php

/**
* Implementation of theme_pager().
*/
function YOURTHEME_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 5) {
  global
$pager_page_array, $pager_total;
 
$tags = array("« first", "‹ previous", "", "next ›", "last »");

 

// Calculate various markers within this pager piece:
  // Middle is used to "center" pages around the current page.
 
$pager_middle = ceil($quantity / 2);
 
// current is the page we are currently paged to
 
$pager_current = $pager_page_array[$element] + 1;
 
// first is the first page listed by this pager piece (re quantity)
 
$pager_first = $pager_current - $pager_middle + 1;
 
// last is the last page listed by this pager piece (re quantity)
 
$pager_last = $pager_current + $quantity - $pager_middle;
 
// max is the maximum page number
 
$pager_max = $pager_total[$element];
 
// End of marker calculations.

  // Prepare for generation loop.
 

$i = $pager_first;
  if (
$pager_last > $pager_max) {
   
// Adjust "center" if at end of query.
   
$i = $i + ($pager_max - $pager_last);
   
$pager_last = $pager_max;
   
$pager_first = $i;
  }
  if (
$i <= 0) {
   
// Adjust "center" if at start of query.
   
$pager_last = $pager_last + (1 - $i);
   
$i = 1;
  }
 
// End of generation loop preparation.

 

$li_first = theme('pager_first', $tags[0], $limit, $element, $parameters);
 
$li_previous = theme('pager_previous', $tags[1], $limit, $element, 1, $parameters);
 
$li_next = theme('pager_next', $tags[3], $limit, $element, 1, $parameters);
 
$li_last = theme('pager_last', $tags[4], $limit, $element, $parameters);

  if (

$pager_total[$element] > 1) {
   
// Add pager first link
   
if ($li_first) {
     
$items[] = array(
       
'class' => 'pager-first',
       
'data' => $li_first,
      );
    }
   
// Add pager previous link
   
if ($li_previous) {
     
$items[] = array(
       
'class' => 'pager-previous',
       
'data' => $li_previous,
      );
    }

   

// When there is more than one page, create the pager list.
    // Middle items start
   
if ($i != $pager_max) {
     
// Now generate the actual pager piece.
     
for (; $i <= $pager_last && $i <= $pager_max; $i++) {
        if (
$i < $pager_current) {
          if (
$pager_first > 1 && $i == $pager_first) {
           
// Add pager breaker
           
$items[] = array(
             
'class' => 'pager-breaker',
             
'data' => '...',
            );           
          }
         
$items[] = array(
           
'class' => 'pager-item',
           
'data' => theme('pager_previous', $i, $limit, $element, ($pager_current - $i), $parameters),
          );
        }
        if (
$i == $pager_current) {
         
$items[] = array(
           
'class' => 'pager-current',
           
'data' => $i,
          );
        }
        if (
$i > $pager_current) {
         
$items[] = array(
           
'class' => 'pager-item',
           
'data' => theme('pager_next', $i, $limit, $element, ($i - $pager_current), $parameters),
          );

          if (

$pager_last < $pager_max && $i == $pager_last) {
           
// Add pager breaker
           
$items[] = array(
             
'class' => 'pager-breaker',
             
'data' => '...',
            );
           
$items[] = array(
             
'class' => 'pager-item',
             
'data' => theme('pager_last', $pager_max, $limit, $element, $parameters),
            );           
          }         
        }
      }
    }
   
// Middle items end
   
    // Add next pager link
   
if ($li_next) {
     
$items[] = array(
       
'class' => 'pager-next',
       
'data' => $li_next,
      );
    }
   
// Add last pager link
   
if ($li_last) {
     
$items[] = array(
       
'class' => 'pager-last',
       
'data' => $li_last,
      );
    }   
   
    return
theme('item_list', $items, NULL, 'ul', array('class' => 'mdPager'));
  }
}
?>

just check if $li_previous or $li_next is blank and set with simple text.

// Setting if previous page exists
$li_previous = theme('pager_previous', (isset($tags[1]) ? $tags[1] : t('‹ Prev Page')), $limit, $element, 1, $parameters);

// Check if any theme input recieved, otherwise set with simple text to show
if (!$li_previous) {
  $li_previous = t('‹ Prev Page');
}

Same is to done with $li_next

// Setting if next page exists
$li_next = theme('pager_next', (isset($tags[3]) ? $tags[3] : t('Next Page ›')), $limit, $element, 1, $parameters);

// Check if any theme input recieved, otherwise set with simple text to show
if (!$li_next) {
  $li_next = t('Next Page ›');
}

Best of luck..

Ok so i'm a bit new to this all, but i now added this code to my template.php and all seems to work OK.

But i was thinking i only wanted to use this special pager for one view I created... how could i adjust the page template code, so it only shows for the view i created?

I've made some small adjustments to the standard implmentation so that you get a pager like this:
< previous 1-50 | 51 - 60 | ... next >

Here is my code:

<?php
/**
* Implementation of theme_pager();
* @tags
* @limit: items per pager
* @element
* @parameters
* @quantity
*/

function yourtheme_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 9) {
  global
$pager_page_array, $pager_total, $pager_total_items
 
 
// Calculate various markers within this pager piece:
  // Middle is used to "center" pages around the current page.
 
$pager_middle = ceil($quantity / 2);
 
// current is the page we are currently paged to
 
$pager_current = $pager_page_array[$element] + 1;
 
// first is the first page listed by this pager piece (re quantity)
 
$pager_first = $pager_current - $pager_middle + 1;
 
// last is the last page listed by this pager piece (re quantity)
 
$pager_last = $pager_current + $quantity - $pager_middle;
 
// max is the maximum page number
 
$pager_max = $pager_total[$element];
 
// End of marker calculations.

  // Prepare for generation loop.
 

$i = $pager_first;
  if (
$pager_last > $pager_max) {
   
// Adjust "center" if at end of query.
   
$i = $i + ($pager_max - $pager_last);
   
$pager_last = $pager_max;
  }
  if (
$i <= 0) {
   
// Adjust "center" if at start of query.
   
$pager_last = $pager_last + (1 - $i);
   
$i = 1;
  }
 
// End of generation loop preparation.

 

$li_first = theme('pager_first', (isset($tags[0]) ? $tags[0] : t('« first')), $limit, $element, $parameters);
 
$li_previous = theme('pager_previous', (isset($tags[1]) ? $tags[1] : t('‹ previous')), $limit, $element, 1, $parameters);
 
$li_next = theme('pager_next', (isset($tags[3]) ? $tags[3] : t('next ›')), $limit, $element, 1, $parameters);
 
$li_last = theme('pager_last', (isset($tags[4]) ? $tags[4] : t('last »')), $limit, $element, $parameters);

  if (

$pager_total[$element] > 1) {
    if (
$li_first) {
     
$items[] = array(
       
'class' => 'pager-first',
       
'data' => $li_first,
      );
    }
    if (
$li_previous) {
     
$items[] = array(
       
'class' => 'pager-previous',
       
'data' => $li_previous,
      );
    }

   

// When there is more than one page, create the pager list.
   
if ($i != $pager_max) {
      if (
$i > 1) {
       
$items[] = array(
         
'class' => 'pager-ellipsis',
         
'data' => '…',
        );
      }
     
// Now generate the actual pager piece.
     
for (; $i <= $pager_last && $i <= $pager_max; $i++) {
        if (
$i < $pager_current) {//previous

           

$min = (($limit * $i) - $limit) + 1;
           
$max = $limit * $i;
           
$text = $min.' - '.$max;
                   
         
$items[] = array(
           
'class' => 'pager-item',
           
'data' => theme('pager_previous', $text, $limit, $element, ($pager_current - $i), $parameters),
          );    
        }
       
        if (
$i == $pager_current) {//current
            //check if we are on the first page
           
if($pager_current == 1){
               
$text = $pager_current.' - '.$limit;
            }else{
               
$min = (($pager_current-1) * $limit)+1;
               
               
//check if we are on the last page, max = min + rest
               
if($i == $pager_max){
                   
$rest = $pager_total_items[0] % $limit;
                   
$max = ($min + $rest) - 1;
                }else{
                 
$max = $limit * $i;
                }
               
$text = $min.' - '.$max;
            }
           
         
$items[] = array(
           
'class' => 'pager-current',
           
'data' => $text,
          );     
        }
       
        if (
$i > $pager_current) {//next
                   
                   
$min = (($limit * $i) - $limit) + 1;
                                       
            if(
$i == $pager_max){
               
$rest = $pager_total_items[0] % $limit;
               
$max = ($min + $rest) - 1;
            }else{
             
$max = $limit * $i;
            }
           
           
$text = $min.' - '.$max;
           
         
$items[] = array(
           
'class' => 'pager-item',
           
'data' => theme('pager_next', $text, $limit, $element, ($i - $pager_current), $parameters),
          );
        }
      }
      if (
$i < $pager_max) {//bigger then pager_max
       
$items[] = array(
         
'class' => 'pager-ellipsis',
         
'data' => '…',
        );
      }
    }
   
// End generation.
   
if ($li_next) {
     
$items[] = array(
       
'class' => 'pager-next',
       
'data' => $li_next,
      );
    }
    if (
$li_last) {
     
$items[] = array(
       
'class' => 'pager-last',
       
'data' => $li_last,
      );
    }
    return
theme('item_list', $items, NULL, 'ul', array('class' => 'pager'));
  }
}
?>

how would you apply a theme to one pager in particular? i want to theme two pagers differently because i limited the count on one.

I'm new to Drupal and trying to figure this out.
I have the pagination working, but I was wondering if there is a way to append the URL so that you can use the browser's back/forward buttons. Any Ideas?

If you want to style a pager like:
← 1 … 5 6 7 8 [9] 10 11 12 13 … 15 →
you need to place this theme function in your template.php:

function yourtheme_pager($variables) {
  $tags = $variables['tags'];
  $element = $variables['element'];
  $parameters = $variables['parameters'];
  $quantity = $variables['quantity'];
  global $pager_page_array, $pager_total;

  // Add js code for Ctrl+arrows navigation
  global $theme_path;
  drupal_add_js($theme_path .'/js/jquery.paginatior.js' );
  $tags[1] = '←';
  $tags[0] = $pager_page_array[$element] > 4 ? '1' : '';
  $tags[3] = '→';
  $tags[4] = $pager_total[$element];
 
  // Calculate various markers within this pager piece:
  // Middle is used to "center" pages around the current page.
  $pager_middle = ceil($quantity / 2);
  // current is the page we are currently paged to
  $pager_current = $pager_page_array[$element] + 1;
  // first is the first page listed by this pager piece (re quantity)
  $pager_first = $pager_current - $pager_middle + 1;
  // last is the last page listed by this pager piece (re quantity)
  $pager_last = $pager_current + $quantity - $pager_middle;
  // max is the maximum page number
  $pager_max = $pager_total[$element];
  // End of marker calculations.

  // Prepare for generation loop.
  $i = $pager_first;
  if ($pager_last > $pager_max) {
    // Adjust "center" if at end of query.
    $i = $i + ($pager_max - $pager_last);
    $pager_last = $pager_max;
  }
  if ($i <= 0) {
    // Adjust "center" if at start of query.
    $pager_last = $pager_last + (1 - $i);
    $i = 1;
  }
  // End of generation loop preparation.

   $li_previous/*$li_first*/ = theme('pager_first', array('text' => (isset($tags[0]) ? $tags[0] : t('« first')), 'element' => $element, 'parameters' => $parameters));
   $li_first = theme('pager_previous', array('text' => (isset($tags[1]) ? $tags[1] : t('‹ previous')), 'element' => $element, 'interval' => 1, 'parameters' => $parameters));
   $li_last = theme('pager_next', array('text' => (isset($tags[3]) ? $tags[3] : t('next ›')), 'element' => $element, 'interval' => 1, 'parameters' => $parameters));
   $li_next /*$li_last*/ = theme('pager_last', array('text' => (isset($tags[4]) ? $tags[4] : t('last »')), 'element' => $element, 'parameters' => $parameters));

  if ($pager_page_array[$element] < 5) $li_previous = '';
  if ($pager_page_array[$element] > $pager_total[$element] - 6) $li_next = '';
 
  if ($pager_total[$element] > 1) {
    if ($li_first) {
      $items[] = array(
        'class' => array('pager-first'),
        'data' => $li_first,
      );
    }
    if ($li_previous) {
      $items[] = array(
        'class' => array('pager-previous'),
        'data' => $li_previous,
      );
    }

    // When there is more than one page, create the pager list.
    if ($i != $pager_max) {
      if ($i > 1) {
        $items[] = array(
          'class' => array('pager-ellipsis'),
          'data' => '…',
        );
      }
      // Now generate the actual pager piece.
      for (; $i <= $pager_last && $i <= $pager_max; $i++) {
        if ($i < $pager_current) {
          $items[] = array(
            'class' => array('pager-item'),
            'data' => theme('pager_previous', array('text' => $i, 'element' => $element, 'interval' => ($pager_current - $i), 'parameters' => $parameters)),
          );
        }
        if ($i == $pager_current) {
          $items[] = array(
            'class' => array('pager-current'),
            'data' => $i,
          );
        }
        if ($i > $pager_current) {
          $items[] = array(
            'class' => array('pager-item'),
            'data' => theme('pager_next', array('text' => $i, 'element' => $element, 'interval' => ($i - $pager_current), 'parameters' => $parameters)),
          );
        }
      }
      if ($i < $pager_max) {
        $items[] = array(
          'class' => array('pager-ellipsis'),
          'data' => '…',
        );
      }
    }
    // End generation.
    if ($li_next) {
      $items[] = array(
        'class' => array('pager-next'),
        'data' => $li_next,
      );
    }
    if ($li_last) {
      $items[] = array(
        'class' => array('pager-last'),
        'data' => $li_last,
      );
    }
    return '<h2 class="element-invisible">' . t('Pages') . '</h2>' . theme('item_list', array(
      'items' => $items,
      'attributes' => array('class' => array('pager')),
    ));
  }
}

Also you need js/jquery.paginatior.js file, which contains:

if (Drupal.jsEnabled) {

  paginator = function () {

    /**
     *  Private properties
     */
    var linkNext = null;
    var linkPrev = null;

    /**
     *  Private methods
     */
    var setLinks = function () {
      linkPrev = $("ul.pager li.pager-previous a").attr("href");
      linkNext = $("ul.pager li.pager-next a").attr("href");
    }

    var navigate = function (event) {
      var href = null;    
      if ( event.ctrlKey && event.keyCode == 37 ) href = linkPrev;
      if ( event.ctrlKey && event.keyCode == 39 ) href = linkNext;
      if ( href ) document.location = href;
    }
   
     /**
       *  Public methods
       */
    this.__init = function () {
      // Get next/prev hrefs
      setLinks();
      // Ctrl + arrow event handle
      $(document).keydown( function(event) {
        navigate(event);
      });
    }
  }
 
  $(document).ready(function(){
    var pageNavigation = new paginator();
    pageNavigation.__init();
  });
}

p.s. It is for Drupal 7