A while back when I was working on The Time theme, I forgot to add pagination navigation… As a result, sites using this theme could only display the first page of articles without the ability to navigate to the next page. Some users opted for plugins to solve this problem. Today I found a tutorial — an oldie but a goodie from Mumu.
1. Add the Function Code to functions.php (within the PHP loop)
function par_pagenavi($range = 9) {
global $paged,
$wp_query;
if (!$max_page) {
$max_page = $wp_query - >max_num_pages;
}
if ($max_page > 1) {
if (!$paged) {
$paged = 1;
}
if ($paged != 1) {
echo "<a href='".get_pagenum_link(1)."' class='extend' title='Jump to first page'> First Page </a>";
}
previous_posts_link(' Previous ');
if ($max_page > $range) {
if ($paged < $range) {
for ($i = 1; $i <= ($range + 1); $i++) {
echo "<a href='".get_pagenum_link($i)."'";
if ($i == $paged) echo " class='current'";
echo ">$i</a>";
}
}
elseif($paged >= ($max_page - ceil(($range / 2)))) {
for ($i = $max_page - $range; $i <= $max_page; $i++) {
echo "<a href='".get_pagenum_link($i)."'";
if ($i == $paged) echo " class='current'";
echo ">$i</a>";
}
}
elseif($paged >= $range && $paged < ($max_page - ceil(($range / 2)))) {
for ($i = ($paged - ceil($range / 2)); $i <= ($paged + ceil(($range / 2))); $i++) {
echo "<a href='".get_pagenum_link($i)."'";
if ($i == $paged) echo " class='current'";
echo ">$i</a>";
}
}
} else {
for ($i = 1; $i <= $max_page; $i++) {
echo "<a href='".get_pagenum_link($i)."'";
if ($i == $paged) echo " class='current'";
echo ">$i</a>";
}
}
next_posts_link(' Next ');
if ($paged != $max_page) {
echo "<a href='".get_pagenum_link($max_page)."' class='extend' title='Jump to last page'> Last Page </a>";
}
}
}
2. Add Styling to Your Theme’s style.css
.page_navi{width:100%;height:36px;line-height:36px;text-align:center;overflow:hidden;padding-top:1em;}
.page_navi a{padding:3px 8px;margin:2px;text-decoration:none;color:#888;border:1px solid #ccf;}
.page_navi a:hover,.page_navi a.current{border:1px solid #356aa0;color:#356aa0;font-weight:bolder;}
3. Add the Function Call to index.php, archive.php, category.php, and search.php
<div> par_pagenavi(9); </div>
Note: This article is reposted from Mumumumumumu