|
效果:
將下面的函數(shù)放到你的主題的 functions.php 文件中:
復(fù)制代碼 代碼如下:
function theme_echo_pagenavi(){
global $request, $posts_per_page, $wpdb, $paged;
$maxButtonCount = 9; //顯示的最多鏈接數(shù)目
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="'.get_pagenum_link().'"><span>首頁</span></a>';
echo '<a href="'.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="'.get_pagenum_link($i).'"><span class="page_num">['.$i.']</span></a>';
}
}
if($paged == $max_page){
echo "<span></span>";
echo "<span>末頁</span> ";
}else{
echo '<a href="'.get_pagenum_link($paged+1).'"><span></span></a>';
echo '<a href="'.get_pagenum_link($max_page).'"><span>末頁</span></a>';
}
echo " 共{$numposts}條記錄, {$max_page}頁.";
}
}
在主題的 index.php 文件中這樣引用:
復(fù)制代碼 代碼如下:
<?php theme_echo_pagenavi(); ?>
php技術(shù):Wordpress php 分頁代碼,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。