Wordpressphp paging code. Effect: put the following functions in the functions. php file of your topic: Copy the code as follows: functiontheme_echo_pagenavi () {global $ request, $ posts_per_page, $ wpdb, $ paged; effect:
Put the following functions in the functions. php file of your topic:
The code is as follows:
Function theme_echo_pagenavi (){
Global $ request, $ posts_per_page, $ wpdb, $ paged;
$ MaxButtonCount = 9; // The maximum number of displayed links
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 "homepage ";
Echo "previous page ";
} 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 'Last page ';
}
Echo "{$ numposts} records in total, {$ max_page} page .";
}
}
Reference in the index. php file of the topic as follows:
The code is as follows:
Handler puts the following functions in the functions. php file of your topic: the code is as follows: function theme_echo_pagenavi () {global $ request, $ posts_per_page, $ wpdb, $ paged ;...