WordPress Theme Add Article List page number navigation PHP code example, _php tutorial

Source: Internet
Author: User

WordPress Theme Add the article List page number navigation PHP code instance,


WordPress default to the theme developer's suggestion is to provide a page-up button at the bottom of the article List, so there is no direct use of the page navigation under the article List function. Here I provide a more complete paging navigation function.

/** *wordpress article List paging navigation *http://www.endskin.com/page-navi/*/function Bing_get_pagenavi ($query = False, $num = False, $b Efore = ', $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 ' + __ (' «Home ', ' Bing '), ' last_text ' + __ ( ' Last» ', ' Bing ', ' next_text ' = ' + ' ('» ', ' Bing '), ' prev_text ' + ' «', ' dotright_text ' = ' ... ', ' d Otleft_text ' + ' ... ', ' num_pages ' and 5, ' always_show ' and ' 0, ' num_larger_page_numbers ' + 3, ' Larg  Er_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 ']);  $larger _page_to_show = intval ($options [' num_larger_page_numbers ']);  $larger _page_multiple = intval ($options [' larger_page_numbers_multiple ']);  $pages _to_show_minus_1 = $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 _page_start;  if ($start _page <= 0) $start _page = 1;  $end _page = $paged + $half _page_end;  if ($end _page-$start _page)! = $pages _to_show_minus_1) $end _page = $start _page + $pages _to_show_minus_1;    if ($end _page > $max _page) {$start _page = $max _page-$pages _to_show_minus_1;  $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) + $largEr_page_multiple)-$larger _per_page;  $larger _start_page_end = Floor ($start _page/10) * + $larger _page_multiple;  $larger _end_page_start = Floor ($end _page/10) * + $larger _page_multiple;  $larger _end_page_end = Floor ($end _PAGE/10) * + ($larger _per_page); if ($larger _start_page_end-$larger _page_multiple = = $start _page) {$larger _start_page_start = $larger _start_page_star    T-$larger _page_multiple;  $larger _start_page_end = $larger _start_page_end-$larger _page_multiple;  } if ($larger _start_page_start <= 0) $larger _start_page_start = $larger _page_multiple;  if ($larger _start_page_end > $max _page) $larger _start_page_end = $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% ', number_f    ormat_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 ($larger _page_to_show > 0 && $larger _start_page_start > 0 && $larger _start_page_end <= $m Ax_page) {for ($i = $larger _start_page_start; $i < $larger _start_page_end; $i + = $larger _page_multiple) {$p        Age_text = Str_replace ('%page_number% ', number_format_i18n ($i), $options [' Page_text ']); Echo '. $page _text.      '';    }} previous_posts_link ($options [' prev_text ']); for ($i = $start _page; $i <= $end _page; $i + +) {if ($i = = $paged) {$current _page_text = Str_repl        Ace ('%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_forma      t_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 want to use the pager:

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

Articles you may be interested in:

    • Analysis of function and basic usage of hook hook in WordPress
    • WordPress enables themes to support gadgets and add plug-in enable functions
    • The basic method of compiling simple code format label in WordPress

http://www.bkjia.com/PHPjc/1084562.html www.bkjia.com true http://www.bkjia.com/PHPjc/1084562.html techarticle WordPress Theme Add the Article List page page number navigation PHP code instance, WordPress default to the theme developer's suggestion is to provide the next page button at the bottom of the article List, so did not provide ...

  • 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.