效果:
将下面的函数放到你的主题的 functions.PHP 文件中:
代码如下:
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',$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 "首页@H_502_29@";
echo "上一页@H_502_29@";
}else{
echo '首页';
echo '上一页';
}
for($i=$start; $i<=$end; $i++){
if($i == $paged) {
echo "502_29@";
} else {
echo '';
}
}
if($paged == $max_page){
echo "下一页@H_502_29@";
echo "末页@H_502_29@ ";
}else{
echo '下一页';
echo '末页';
}
echo " 共{$numposts}条记录,{$max_page}页.";
}
}
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',$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 "首页@H_502_29@";
echo "上一页@H_502_29@";
}else{
echo '首页';
echo '上一页';
}
for($i=$start; $i<=$end; $i++){
if($i == $paged) {
echo "502_29@";
} else {
echo '';
}
}
if($paged == $max_page){
echo "下一页@H_502_29@";
echo "末页@H_502_29@ ";
}else{
echo '下一页';
echo '末页';
}
echo " 共{$numposts}条记录,{$max_page}页.";
}
}
在主题的 index.PHP 文件中这样引用:
代码如下: