Add the PHP code instance _ php instance in the page number navigation of the article list page in the WordPress topic

Source: Internet
Author: User
This article mainly introduces the PHP code instance for adding page number navigation to the WordPress topic, which is also an essential basic function for creating various WordPress Themes, if you want to use WordPress, you can refer to WordPress's default recommendation for Topic developers to provide the top and bottom buttons at the bottom of the article list. Therefore, you do not provide paging navigation functions that are directly used in the article list. Here I provide a complete paging navigation function.

/*** WordPress article list page navigation * http://www.endskin.com/page-navi/#/function Bing_get_pagenavi ($ query = false, $ num = false, $ before = '', $ after ='', $ Options = array () {global $ wp_query; $ options = wp_parse_args ($ options, array ('pages _ text' => '% CURRENT_PAGE %/% TOTAL_PAGES %', 'current _ text' => '% PAGE_NUMBER % ', 'page _ text' => '% PAGE_NUMBER %', 'First _ text' => _ ('« homepage ', 'bing '), 'Last _ text' => _ ('Last page» ', 'bing'), 'next _ text' => _ ('» ', 'bin '), 'prev _ text' => '«', 'dotright _ text' => '... ', 'dotleft _ text' => '... ', 'num _ page' => 5, 'a Lways_show '=> 0, 'num _ larger_page_numbers' => 3, 'larger _ page_numbers_multiple '=> 10 )); if ($ wp_query-> max_num_pages <= 1 | is_single () return; if (! Empty ($ query) {$ request = $ query-> request; $ numposts = $ query-> found_posts; $ max_page = $ query-> max_num_pages; $ posts_per_page = intval ($ num);} else {$ request = $ wp_query-> request; $ numposts = $ wp_query-> found_posts; $ max_page = $ wp_query-> max_num_pages; $ posts_per_page = intval (get_query_var ('posts _ per_page ');} $ paged = intval (get_query_var ('paged'); if (empty ($ paged) | $ paged = 0) $ paged = 1; $ pages_to_show = intval ($ options ['num _ pages']); $ duration = intval ($ options ['num _ larger_page_numbers ']); $ larger_page_multiple = intval ($ options ['larger _ page_numbers_multiple']); $ duration = $ pages_to_show-1; $ half_page_start = floor ($ pages_to_show_minus_1/2); $ half_page_end = ceil ($ pages_to_show_minus_1/2); $ start_page = $ paged-$ half_pa Ge_start; if ($ start_page <= 0) $ start_page = 1; $ end_page = $ paged + $ half_page_end; if ($ end_page-$ start_page )! = $ Response) $ end_page = $ start_page + $ pages_to_show_minus_1; if ($ end_page> $ max_page) {$ start_page = $ max_page-$ response; $ end_page = $ max_page ;} if ($ start_page <= 0) $ start_page = 1; $ larger_per_page = $ larger_page_to_show * $ larger_page_multiple; $ larger_start_page_start = (floor ($ start_page/10) * 10) + $ larger_page_multiple)-$ larger_per_page; $ larg Er_start_page_end = floor ($ start_page/10) * 10 + $ larger_page_multiple; $ larger_end_page_start = floor ($ end_page/10) * 10 + $ larger_page_multiple; $ response = floor ($ end_page/10) * 10 + ($ larger_per_page); if ($ response-$ larger_page_multiple ==$ start_page) {$ larger_start_page_start = $ response-$ larger_page_multiple; $ larger_start_page_end = $ Example-$ larger_page_multiple;} if ($ larger_start_page_start <= 0) $ larger_start_page_start = $ larger_page_multiple; if ($ example> $ max_page) $ example = $ max_page; if ($ larger_end_page_end> $ max_page) $ larger_end_page_end = $ max_page; if ($ max_page> 1 | intval ($ options ['always _ show']) = 1) {$ pages_text = str_replace ('% CURRENT_PAGE %', numb Er_format_i18n ($ paged), $ options ['pages _ text']); $ pages_text = str_replace ('% TOTAL_PAGES %', number_format_i18n ($ max_page), $ pages_text ); echo $ before; if (! Empty ($ pages_text) echo ''. $ pages_text. ''; if ($ start_page> = 2 & $ pages_to_show <$ max_page) {$ first_page_text = str_replace ('% TOTAL_PAGES %', number_format_i18n ($ max_page ), $ options ['first _ text']); echo ''. $ first_page_text. '';} if ($ response> 0 & $ larger_start_page_start> 0 & $ larger_start_page_end <= $ max_page) {for ($ I = $ larger_start_page_start; $ I <$ larger_start_page_end; $ I + = $ larger_page_multiple) {$ page_text = str_replace ('% PAGE_NUMBER %', number_format_i18n ($ I), $ options ['page _ text']); echo ''. $ page_text. '';} previus_posts_link ($ options ['prev _ text']); for ($ I = $ start_page; $ I <= $ end_page; $ I ++) {if ($ I = $ paged) {$ current_page_text = str_replace ('% PAGE_NUMBER %', number_format_i18n ($ I), $ options ['current _ text']); echo ''. $ current_page_text. '';} else {$ page_text = str_replace ('% PAGE_NUMBER %', number_format_i18n ($ I), $ options ['page _ text']); echo ''. $ page_text. '';}} if (empty ($ query) echo''; next_posts_link ($ options ['Next _ text'], $ max_page ); if (empty ($ query) echo '';} if ($ larger_page_to_show> 0 & $ larger_end_page_start <$ max_page) {for ($ I = $ larger_end_page_start; $ I <= $ larger_end_page_end; $ I + = $ larger_page_multiple) {$ page_text = str_replace ('% PAGE_NUMBER %', number_format_i18n ($ I ), $ options ['page _ text']); echo ''. $ page_text. '';}} if ($ end_page <$ max_page) {$ last_page_text = str_replace ('% TOTAL_PAGES %', number_format_i18n ($ max_page ), $ options ['last _ text']); echo ''. $ last_page_text. '';} echo $ after ;}

Then add the following code where you need to use the paging Navigation:

<?php if( function_exists( 'Bing_get_pagenavi' ) ) Bing_get_pagenavi(); ?>

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.