The paging navigation menu is an essential element of a website. today I will share with you the WordPress code to implement paging navigation.
WordPress's built-in paging navigation is not very good! However, there are too many plug-ins to implement this function, and we have also used WordPress Paginator.
The paging navigation menu is an essential element of a website. today I will share with you the WordPress code to implement paging navigation.
Navigation effect:
The implementation method is as follows:
1. put the following code to the last one in functions. php?> Before
Function par_pagenavi ($ range = 9) {global $ paged, $ wp_query; if (! $ Max_page) {$ max_page = $ wp_query-> max_num_pages;} if ($ max_page> 1) {if (! $ Paged) {$ paged = 1;} if ($ paged! = 1) {echo "back to home";} previus_posts_link ('previous page'); if ($ max_page >$ range) {if ($ paged <$ range) {for ($ I = 1; $ I <= ($ range + 1); $ I ++) {echo "$ I ";}} elseif ($ paged >=( $ max_page-ceil ($ range/2) {for ($ I = $ max_page-$ range; $ I <= $ max_page; $ I ++) {echo "$ I ";}} elseif ($ paged >=$ range & $ paged <($ max_page-ceil ($ range/2 )))) {for ($ I = ($ paged-ceil ($ range/2); $ I <= ($ paged + ceil ($ range/2 ))); $ I ++) {Echo "$ I" ;}}} else {for ($ I = 1; $ I <=$ max_page; $ I ++) {echo "$ I ";}} next_posts_link ('next page'); if ($ paged! = $ Max_page) {echo "last page ";}}
2. add the following css style to your style.css.
.page_navi{overflow:hidden;width:100%;text-align:center}.page_navi a{height:36px;border:1px solid #DDD;-webkit-border-radius:12px;-moz-border-radius:12px;border-radius:12px;color:#888;text-decoration:none;line-height:36px;margin:2px;padding:3px 8px}.page_navi a:hover,.page_navi a.current{border:1px solid #FFBB76;color:#FF7200;font-weight:bolder}
3. add the following call code in the desired area (such as index. php, archive. php, category. php, and search. php of the topic ).
The number above indicates the maximum number of pages displayed. you can modify the number as needed.