Home  >  Article  >  Backend Development  >  Wordpress php pagination code_PHP tutorial

Wordpress php pagination code_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:43:191275browse

Effect:

Put the following function into your theme’s functions.php file:

Copy the code The 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< /span>";
}else{
echo 'Homepage';
echo 'Previous page';
}
for($i=$start; $i<=$end; $i++){
if($i == $paged) {
echo "[$ i]";
} else {
echo '[' .$i.']';
}
}
if($paged == $max_page){
echo "Next page";
echo "last page ";
}else{
echo 'Next page';
echo '< ;span>Last page
';
}
echo "Total {$numposts} records, {$max_page} pages.";
}
}

is quoted like this in the theme’s index.php file:
Copy the code The code is as follows:


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320770.htmlTechArticleEffect: Place the following function into the functions.php file of your theme: Copy the code as follows: function theme_echo_pagenavi(){ global $request, $posts_per_page, $wpdb, $paged;...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn