Effect:
Put the following functions in the functions. php file of your topic:
Copy codeThe 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 "<span> homepage </span> ";
Echo "<span> previous page </span> ";
} Else {
Echo '<a href = "'. get_pagenum_link (). '"> <span> homepage </span> </a> ';
Echo '<a href = "'. get_pagenum_link ($ paged-1). '"> <span> previous page </span> </a> ';
}
For ($ I = $ start; $ I <= $ end; $ I ++ ){
If ($ I = $ paged ){
Echo "<span class = \" page_num on \ "> [$ I] </span> ";
} Else {
Echo '<a href = "'. get_pagenum_link ($ I ). '"> <span class =" page_num "> ['. $ I. '] </span> </a> ';
}
}
If ($ paged = $ max_page ){
Echo "<span> next page </span> ";
Echo "<span> last page </span> ";
} Else {
Echo '<a href = "'. get_pagenum_link ($ paged + 1). '"> <span> next page </span> </a> ';
Echo '<a href = "'. get_pagenum_link ($ max_page). '"> <span> last </span> </a> ';
}
Echo "{$ numposts} records in total, {$ max_page} page .";
}
}
Reference in the index. php file of the topic as follows:
Copy codeThe Code is as follows:
<? Php theme_echo_pagenavi ();?>