function theme_echo_pagenavi(){
global $request, $posts_per_page, $wpdb, $paged;
$maxButtonCount = 9; //显示的最多链接数目
if (!is_single()) {
if(!is_category()) {
preg_match('#FROM\s(.*)\sORDER BY#siU', $request, $matches);
} else {
preg_match('#FROM\s(.*)\sGROUP BY#siU', $request, $matches);
}
$fromwhere = $matches[1];
$numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere");
$max_page = ceil($numposts /$posts_per_page);
if(empty($paged)) {
$paged = 1;
}
$start = max(1, $paged - intval($maxButtonCount/2));
$end = min($start + $maxButtonCount - 1, $max_page);
$start = max(1, $end - $maxButtonCount + 1);
if($paged == 1){
echo "<span>首页</span>";
echo "<span>上一页</span>";
}else{
echo '<a href="'https://www.jb51.net/article/.get_pagenum_link().'"><span>首页</span></a>';
echo '<a href="'https://www.jb51.net/article/.get_pagenum_link($paged-1).'"><span>上一页</span></a>';
}
for($i=$start; $i<=$end; $i++){
if($i == $paged) {
echo "<span class=\"page_num on\">[$i]</span>";
} else {
echo '<a href="'https://www.jb51.net/article/.get_pagenum_link($i).'"><span>['.$i.']</span></a>';
}
}
if($paged == $max_page){
echo "<span>下一页</span>";
echo "<span>末页</span> ";
}else{
echo '<a href="'https://www.jb51.net/article/.get_pagenum_link($paged+1).'"><span>下一页</span></a>';
echo '<a href="'https://www.jb51.net/article/.get_pagenum_link($max_page).'"><span>末页</span></a>';
}
echo " 共{$numposts}条记录, {$max_page}页.";
}
}
Wordpress php 分页代码
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:http://www.heiqu.com/e708089dd5ed79fffa4b3c20ac2a7063.html