效果:
將下面的函數放到你的主題的functions.php 文件中:
複製代碼 程式碼如下:
function theme_echo_pagenavi(){
global $request, $posts_per_page, $wpdb, $paged;
$maxButton = Countdb, $paged;
$maxButton = Countdb9;的最多連結數目
if (!is_single()) {
if(!is_category()) {
preg_match('#FROMs(.*)sORDER BY#siU', $request, $matches) ;
} else {
preg_match('#FROMs(.*)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 "首頁";
echo "上一頁";
}else{
echo '首頁 ';
echo '上一頁';
}
for($i=$start; $iif($i == $paged) {
echo "[$ i]";
} else {
echo '['.$i.'] ';
}
}
if($paged == $max_page){
echo "下一頁";
echo "末頁 ";
}else{
echo '下一頁';
echo '末頁';
}
echo "共{$numposts}筆記錄, {$max_page}頁.";
}
}
複製程式碼
程式碼如下:
以上就介紹了wordpress.com Wordpress php 分頁程式碼,包含了wordpress.com方面的內容,希望對PHP教學有興趣的朋友有幫助。