Custom pager theming examples

Last updated on
30 April 2025

You are browsing documentation for an older version of Drupal, which is not supported any longer, and the information may not be correct. See current documentation for Contributed modules

This is a page of example code and templates for custom pagers. Please add your own!

Using these examples

Theming a custom pager can involve making several changes to your theme:
- creating a function phptemplate_preprocess_custom_pager in your theme's template.php file
- creating template files in your theme folder, eg. custom-pager.tpl.php

In template.php:

function phptemplate_preprocess_custom_pager(&$vars) {
  // if we're at the end, the nav_array item for this (eg first) is NULL;
  // no need to compare it to current index.
  $vars['first'] = empty($vars['nav_array']['first']) ? '' : l('first', 'node/' . $vars['nav_array']['first']);
  $vars['last'] = empty($vars['nav_array']['last']) ? '' : l('last', 'node/' . $vars['nav_array']['last']);
}

Add a custom-pager.tpl.php:

<ul class="custom-pager custom-pager-<?php print $position; ?>">
  <li class="first"><?php print $first; ?></li>
  <li class="previous"><?php print $previous; ?></li>
  <li class="key"><?php print $key; ?></li>
  <li class="next"><?php print $next; ?></li>
  <li class="last"><?php print $last; ?></li>
</ul>

Help improve this page

Page status: Not set

You can: