The paging navigation menu is an essential element of a website. today, I will share with you the method of implementing paging navigation using WordPress code that has been used for a long time by Jiemeng. Navigation effect: the implementation method is very simple. 1. put the following code to the last one of functions. php? & Gt; functiontwentytw
The paging navigation menu is an essential element of a website. today, I will share with you the method of implementing paging navigation using WordPress code that has been used for a long time by Jiemeng.
Navigation effect:
The implementation method is very simple. let's take a look.
1. put the following code to the last one in functions. php?> Before
Function twentytwelve_page_nav ($ range = 5) {global $ paged, $ wp_query; $ max_page = $ wp_query-> max_num_pages; if ($ max_page> 1) {if (! $ Paged) {$ paged = 1;} if ($ paged> 1) {echo "back to home"; previous_posts_link ('previous paged ');} if ($ max_page <= $ range | $ paged <= 3) {// if the maximum page number is less than the display page range $ range, or the incoming page number is less than or equal to 3, the first five pages are displayed for ($ I = 1; $ I <= $ max_page; $ I ++) {echo "$ I ";}} elseif ($ max_page> $ range & $ paged <$ max_page-5) {// if the maximum page number $ max_page is greater than the display page number range $ range, the front and back pages of the current page (including their own) are displayed with 5 pages $ pages = range ($ paged-2, $ paged +); for ($ I = 0; I <5; $ I ++) {echo "$ pages [I]" ;}} Else {// if the maximum page number $ max_page is greater than the display page number range $ range and is already the last five pages, the last five pages are displayed for ($ I = $ paged; $ 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 #f40; color:#f40; font-weight:bold;}
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.