将下面的函数放到你的主题的 functions.php 文件中:
function theme_echo_pagenavi(){
global $wp_query;
global $request, $posts_per_page, $wpdb, $paged;
$maxButtonCount = 9; //显示的最多链接数目
$current_page = $paged;
$current_page = $paged;
if(empty($current_page)) {
$current_page = 1;
}
$numposts = $wp_query->found_posts;
$max_page = $wp_query->max_num_pages;
$start = max(1, $current_page - intval($maxButtonCount/2));
$end = min($start + $maxButtonCount - 1, $max_page);
$start = max(1, $end - $maxButtonCount + 1);
if($current_page <= 1){
echo "<span>|<</span>";
echo "<span><<</span>";
}else{
echo '<a href="'.get_pagenum_link().'"><span>|<</span></a>';
echo '<a href="'.get_pagenum_link($current_page-1).'"><span><<</span></a>';
}
for($i=$start; $i<=$end; $i++){
if($i == $current_page) {
echo "<span class=\"page_num on\">$i</span>";
} else {
echo '<a href="'.get_pagenum_link($i).'"><span class="page_num">'.$i.'</span></a>';
}
}
if($current_page >= $max_page){
echo "<span>>></span>";
echo "<span>>|</span> ";
}else{
echo '<a href="'.get_pagenum_link($current_page+1).'"><span>>></span></a>';
echo '<a href="'.get_pagenum_link($max_page).'"><span>>|</span></a>';
}
echo " {$current_page}/{$max_page}页, {$numposts}条记录.";
}
在主题的 index.php 文件中这样引用:
<?php theme_echo_pagenavi(); ?>