Adding the following snippet to your theme’s functions.php file, you will be able to paginate WordPress posts.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <?php function wp_paginate($pgs = '', $rng = 2) { $itm = ($rng * 2) + 1; global $pgd; if (empty($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) echo "<a href='" . get_pagenum_link(1) . "'>«</a>"; if ($pgd > 1 && $itm < $pgs) echo "<a href='" . get_pagenum_link($pgd - 1) . "'>‹</a>"; 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) echo "<a href='" . get_pagenum_link($pgd + 1) . "'>›</a>"; if ($pgd < $pgs - 1 && $pgd + $rng - 1 < $pgs && $itm < $pgs) echo "<a href='" . get_pagenum_link($pgs) . "'>»</a>"; echo "</div>\n"; } } ?> |
Snippet Source/Credit: Design-Ninja