You are here

theme_sample.php in Custom Pagers 5

File

theme_sample.php
View source

// This function is an alternative to the standard Custom Pager theming function. It was used in
// earlier versions of the module, but was removed to eliminate the node_load() calls for each
// page in on high-traffic sites. Now, it provides an example of yet-another-way the pagers can
// be themed.

function my_theme_custom_pager($nav_array, $node, $pager) {
  drupal_add_css(drupal_get_path('module', 'custom_pagers') .'/custom_pagers.css');

  if (is_numeric($nav_array['prev'])) {
    $prev = node_load($nav_array['prev']);
  }
  if (is_numeric($nav_array['next'])) {
    $next = node_load($nav_array['next']);
  }

  if ($prev || $next) {
    if ($prev) {
      $links[] = l(t('‹ ') . $prev->title, 'node/'. $prev->nid, array('class' => 'pager-previous', 'title' => $prev->title));
    }

    // Word break (a is an inline element)
    $links[] = '<span class="pager-count">'. ($nav_array['current_index'] + 1) .' of '. count($nav_array['full_list']) .'</span>';

    if ($next) {
      $links[] = l($next->title . t(' ›'), 'node/'. $next->nid, array('class' => 'pager-next', 'title' => $next->title));
    }

    $output .= '<div class="custom-pager custom-pager-' . $node->type . '">' . implode(' ', $links) . '</div>';
  }

  return $output;
}