Effect:
Put the following function into your theme’s functions.php file:
Copy the codeThe code is as follows:
function theme_echo_pagenavi(){
global $request, $posts_per_page , $wpdb, $paged;
$maxButtonCount = 9; //The maximum number of links displayed
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 "Homepage";
echo "Previous Page ";
}else{
echo 'Homepage';
echo 'Previous page';
}
for($i=$start; $i<=$ end; $i++){
if($i == $paged) {
echo "[$i]";
} else {
echo '< ;a href="'.get_pagenum_link($i).'">['.$i.']';
}
}
if($paged == $max_page){
echo "next page";
echo "last page ";
}else{
echo 'Next page';
echo 'Last page';
}
echo " Total {$numposts} records, {$max_page} pages.";
}
}
Copy the code The code is as follows:
The above introduces the wordpress.com Wordpress php paging code, including the content of wordpress.com. I hope it will be helpful to friends who are interested in PHP tutorials.