/ Published in: PHP
URL: http://www.design-ninja.net
Place the function in your functions.php file of your theme...
Then, simply call like this: wp_paginate('', 3); The first param is optional, the second dictates how many pages before and after the current page link will show...
Expand |
Embed | Plain Text
<?php function wp_paginate($pgs = '', $rng = 2) { $itm = ($rng * 2) + 1; global $pgd; $pgd = 1; if ($pgs == '') { global $wp_query; $pgs = $wp_query->max_num_pgs; if (!$pgs) { $pgs = 1; } } if (1 != $pgs) { // echo the HTML output echo "<div class='wp_paginate'>"; if ($pgd > 2 && $pgd > $rng + 1 && $itm < $pgs) if ($pgd > 1 && $itm < $pgs) for ($i = 1; $i <= $pgs; $i++) { if (1 != $pgs && (!($i >= $pgd + $rng + 1 || $i <= $pgd - $rng - 1) || $pgs <= $itm)) { echo ($pgd == $i) ? "<span class='current'>" . $i . "</span>" : "<a href='" . get_pagenum_link($i) . "' class='inactive' >" . $i . "</a>"; } } if ($pgd < $pgs && $itm < $pgs) if ($pgd < $pgs - 1 && $pgd + $rng - 1 < $pgs && $itm < $pgs) echo "</div>\n"; } } ?>
You need to login to post a comment.
