WordPress Theme Add Article List page page number navigation PHP code instance _php instance

Source: Internet
Author: User

WordPress defaults to the theme developer's recommendation is to provide a page DOWN button at the bottom of the list of articles, so there is no function for paging navigation that is directly used under the list of articles. Here I provide a more complete pager function.

/** *wordpress article List paging navigation *http://www.endskin.com/page-navi//function Bing_get_pagenavi ($query = false, $num = Fals E, $before = ' <article class= ' Pagenavi postlistpagenavi ' > ', $after = ' </article> ', $options = Array ()) {Glo
  Bal $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 ' =&gt ; 
    __ (' Last» ', ' Bing '), ' Next_text ' => __ ('» ', ' Bing '), ' Prev_text ' => ' «', ' Dotright_text ' => ' ... ', ' Dotleft_text ' => ' ... ', ' num_pages ' => 5, ' Always_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 ']);
  $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_sta
    rt-$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_
    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 ' <span class= ' pages ' > '. $pages _text.
    ' </span> ';  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 ' <a href= '. Esc_url (Get_pagenum_link ()). ' class= ', ' title= '. $first _page_text. ' > '. $first _page_text.
    ' </a> '; } if ($larger _page_to_show > 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 ' <a href= '. Esc_url (Get_pagenum_link ($i)). ' "class=" page "title=". $page _text. ' > '. $page _text.
      ' </a> ';
    } previous_posts_link ($options [' prev_text ']); for ($i = $start _page $i <= $end _page $i + +) {if ($i = = $paged) {$current _page_text = str_re
        Place ('%page_number% ', number_format_i18n ($i), $options [' Current_text ']); Echo ' <span class= ' current ' > '. $current _page_text.
      ' </span> ';
        }else{$page _text = str_replace ('%page_number% ', number_format_i18n ($i), $options [' Page_text ']); Echo ' <a href= '. Esc_url (Get_pagenum_link ($i)). "Class=" page "title=". $page _text. ' > '. $page _text.
      ' </a> ';
    } if (empty ($query)) echo ' <span id= ' next-page ' >;
    Next_posts_link ($options [' Next_text '], $max _page); if (empty ($query))Echo ' </span> '; } if ($larger _page_to_show > 0 && $larger _end_page_start < $max _page) {for ($i = $larger _end_page_sta RT; $i <= $larger _end_page_end $i + + $larger _page_multiple) {$page _text = str_replace ('%page_number% ', NUMBER_FO
      rmat_i18n ($i), $options [' Page_text ']); Echo ' <a href= '. Esc_url (Get_pagenum_link ($i)). "Class=" page "title=". $page _text. ' > '. $page _text.
    ' </a> '; } if ($end _page < $max _page) {$last _page_text = str_replace ('%total_pages% ', number_format_i18n ($max _page
    ), $options [' Last_text ']); Echo ' <a href= '. Esc_url (Get_pagenum_link ($max _page)). "Class=" Last "title=". $last _page_text. ' > '. $last _page_text.
  ' </a> ';
Echo $after;
 }

Then add the following code where you want to use the pager:

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