WordPress code-only, implementing paging navigation menu

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.