Home >Backend Development >PHP Tutorial >wordpress.com Wordpress php pagination code

wordpress.com Wordpress php pagination code

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-29 08:40:59831browse

Effect:

 Wordpress php 分页代码

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.";
}
}


Quote like this in the index.php file of the theme:

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.

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