/ Published in: PHP
All code should ideally go into your theme\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'s template.php file. I\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'ve used the default Garland theme here as an example.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Return themed pager using same markup and CSS classes as the standard Drupal pager. * * @param $total_pages total no. of pages. * @param $current_page the current page being viewed (1 <= $current_page <= $total_pages). * @param $num_pages_to_show no. of pages links for, excluding first, next, previous and last links . * @param $base_url the base URL for paging links. Each paging link will be at $base_url?page=<page_num> * @return themed paging links; empty string if there is only one page in total. */ function garland_simple_pager_links($total_pages, $current_page, $num_pages_to_show, $base_url) { static $buttons; ); } // show nothing if only one page if (1 >= $total_pages) return ''; // remove all query params from the base URL // the first page in current set of pages // the last page in current set of pages // normalize if (1 > $pager_first) { $pager_last += (1 - $pager_first); $pager_first = 1; } if ($total_pages < $pager_last) { $pager_first -= ($pager_last - $total_pages); if (1 > $pager_first) $pager_first = 1; $pager_last = $total_pages; } // show 'prev' button if (1 < $current_page) { // show 'first' button if (1 < $pager_first) { 'class' => 'pager-first', 'data' => theme('simple-pager-link', $base_url, 1, $buttons['first']), ); } 'class' => 'pager-previous', 'data' => theme('simple-pager-link', $base_url, $current_page-1, $buttons['prev']), ); // show ellipsis if (1 < $pager_first) { 'class' => 'pager-ellipsis', 'data' => theme('simple-pager-link', $base_url, '...', $buttons['ellipsis']), ); } } // page links for ($i=$pager_first; $i<=$pager_last; ++$i) { if ($i == $current_page) { 'class' => 'pager-current', 'data' => theme('simple-pager-link', $base_url, $i, $buttons['current']), ); } else { 'class' => 'pager-item', ); } } // show 'next' button if ($total_pages > $current_page) { // show ellipsis if ($total_pages > $pager_last) { 'class' => 'pager-ellipsis', 'data' => theme('simple-pager-link', $base_url, '...', $buttons['ellipsis']), ); } 'class' => 'pager-next', 'data' => theme('simple-pager-link', $base_url, $current_page+1, $buttons['next']), ); // show 'last' button if ($total_pages > $pager_last) { 'class' => 'pager-last', 'data' => theme('simple-pager-link', $base_url, $total_pages, $buttons['last']), ); } } } /** * Return a themed pager link. * * @param $base_url the base URL to add the paging query param to. * @param $page the number of the page to link to. * @param $button_attributes array('link_tooltip' =>, 'text' => 'class' =>). * If 'link_tooltip' is ommitted then the text is returned witout a wrapping anchor. If 'text' is ommitted then * $page is used as the link text. * * @return themed pager link. * @see garland_pager_link() */ function garland_simple_pager_link($base_url, $page, $button_attributes) { ); $attributes['class'] = $button_attributes['class']; } else { return $text; } } // Amend you theme's theme() method accordingly, as I've done below for Garland: function garland_theme($existing, $type, $theme, $path) { 'function' => 'garland_simple_pager_links', ), 'function' => 'garland_simple_pager_link', ) ); }