Example of wordpress's article paging function

Source: Internet
Author: User

Uncle previously introduced many tabs on the wordpress category list and comments, but he hasn't introduced any pages on the content of the article. Today I am free to write a tutorial to learn about it. First of all, wordpress article paging should be implemented from the editor and paging definition functions. Now let's go directly to the tutorial.

First, put the following code in functions. php of the wordpress theme folder.

// Add the "next page" button in the WordPress editor
Add_filter ('mce _ buttons ', 'Add _ next_page_button ');
Function add_next_page_button ($ mce_buttons ){
$ Pos = array_search ('WP _ more ', $ mce_buttons, true );
If ($ pos! = False ){
$ Tmp_buttons = array_slice ($ mce_buttons, 0, $ pos + 1 );
$ Tmp_buttons [] = 'WP _ page ';
$ Mce_buttons = array_merge ($ tmp_buttons, array_slice ($ mce_buttons, $ pos + 1 ));
    }
Return $ mce_buttons;
}

// Content paging
Function custom_wp_link_pages ($ args = ''){
$ Defaults = array (
'Before' => '<div class = "pagelist"> paging reading :',
'After' => '</div> ',
'Text _ before' => '',
'Text _ after' => '',
'Next _ or_number '=> 'number ',
'Nextpagelink '=> 'next page ',
'Previouspagelink '=> 'previous page ',
'Pagelink '=>' % ',
'Echo '=> 1
);
$ R = wp_parse_args ($ args, $ defaults );
$ R = apply_filters ('WP _ link_pages_args ', $ r );
Extract ($ r, EXTR_SKIP );
Global $ page, $ numpages, $ multipage, $ more, $ pagenow;
$ Output = '';
If ($ multipage ){
If ('number' = $ next_or_number ){
$ Output. = $ before;
For ($ I = 1; $ I <($ numpages + 1); $ I = $ I + 1 ){
$ J = str_replace ('%', $ I, $ pagelink );
$ Output. = '';
If ($ I! = $ Page | ((! $ More) & ($ page = 1 )))
$ Output. = _ wp_link_page ($ I );
Else
$ Output. = '<span> ';
$ Output. = $ text_before. $ j. $ text_after;
If ($ I! = $ Page | ((! $ More) & ($ page = 1 )))
$ Output. = '</a> ';
Else
$ Output. = '</span> ';
            }
$ Output. = $ after;
} Else {
If ($ more ){
$ Output. = $ before;
$ I = $ page-1;
If ($ I & $ more ){
$ Output. = _ wp_link_page ($ I );
$ Output. = $ text_before. $ previouspagelink. $ text_after. '</a> ';
                }
$ I = $ page + 1;
If ($ I <= $ numpages & $ more ){
$ Output. = _ wp_link_page ($ I );
$ Output. = $ text_before. $ nextpagelink. $ text_after. '</a> ';
                }
$ Output. = $ after;
            }
        }
    }
If ($ echo)
Echo $ output;
Return $ output;
}

Add the next page button to the editor and define the paging function. Insert the calling function to the corresponding position on the single. php article page to display the paging button on the front end. The calling function is as follows:

<? Php custom_wp_link_pages ();?>

In this step, the page is displayed...

Css I also paste it out, relatively simple... If your css technology has any disadvantages, please share it with us.

. Pagelist {padding: 10px 0; background: # f3f3f3; text-align: center; margin-top: 20px}
. Pagelist> span ,. pagelist> a {background-color: # fff; border: 1px # ddd solid; color: #000; margin-left: 5px; padding: 4px 10px; text-transform: uppercase ;}
. Pagelist> a: hover,. pagelist> span {background-color: #363636; color: # fff! Important ;}

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.