Wordpress function integration (6): no plug-in implemented page number

Source: Internet
Author: User
Many wordpress themes do not have their own page numbers, but are links to "previous pages" and "next pages". However, according to our national habits, it is much easier to have pages. In fact, wordpress has a page number function, there is no need to install a plug-in for such a small feature. Function paginate_links (), which is introduced on the official website

Many wordpress themes do not have their own page numbers, but are links to "previous pages" and "next pages". However, according to our national habits, it is much easier to have pages. In fact, wordpress has a page number function, there is no need to install a plug-in for such a small feature. Function paginate_links (). the official website introduces Retrieve paginated link for archive post pages. Technically, the function can be used to create paginated link list for any area (e.g .:? Prev 1... 3 4 5 6 7... 9 Next? ). However, using this function directly does not display page numbers. you need to configure parameters.

Follow the examples on the official website to add the following function where the page number needs to be displayed to display the page number and the link to the top and bottom pages:

123456789101112 Str_replace ($ big, '% # %', esc_url (get_pagenum_link ($ big), 'format' => '? Paged = % # % ', 'stream' => max (1, get_query_var ('paged'), 'total' => $ wp_query-> max_num_pages);?>

However, this configuration is not very convenient. generally, we define a new function to display the page number. in this way, you do not need to configure these parameters repeatedly during each call. the code page is simpler and easier to modify. Add the page number function to the topic's functions. php file as follows:

1234567891011121314151617181920212223242526 // Page number function wp_pagenavi () {// declare two global variables global $ wp_query, $ wp_rewrite; // determine the current page $ wp_query-> query_vars ['paged']> 1? $ Current = $ wp_query-> query_vars ['paged']: $ current = 1; $ pagination = array ('base' => @ add_query_arg ('paged ', '% # %'), 'format' => '', 'total' => $ wp_query-> max_num_pages, 'current' => $ current, 'show _ all' => false, 'type' => 'plain ', 'end _ size' => '1', 'mid _ size' => '3 ', 'prev _ text' => 'previous page', 'next _ text' => 'next page'); if ($ wp_rewrite-> using_permalinks ()) $ pagination ['base'] = user_trailingslashit (tra Ilingslashit (remove_query_arg ('s ', get_pagenum_link (1). 'Page/% # %/', 'paged'); if (! Emptyempty ($ wp_query-> query_vars ['s']) $ pagination ['add _ args '] = array ('s' => get_query_var ('s ')); echo paginate_links ($ pagination );}

Follow the above function to call this function:

Display effect, of course, I need css to work:


Several frequently modified parameters of the function are as follows:

123456789101112131415161718 '% _ %', 'Format' => '? Page = % # % ', 'total' => 1, // total number of displayed pages 'current' => 0, // Current page number 'show _ all' => False, // whether to display all pages, such as ellipsis in the middle, the following two parameters must be used together with 'end _ size' => 1, // display the minimum number of numbers at the end and the beginning, for example, 1 ,, the last page shows at least one page number "20" 'mid _ size' => 2, // the minimum number of pages displayed before and after the current page number 'prev _ next' => True, // whether the "Previous page" and "next page" links 'prev _ text' => _ ('« Previous ') are displayed '), // The text 'next _ text' => _ ('next» ') displayed on the "previous page" link »'), // The text 'type' => 'plain ', 'Add _ args' => False, 'Add _ fragment '=>);?>

The viewer can modify the configuration parameters in the function.

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.