Wordpress function integration (8) button for adding a tab in the editor

Source: Internet
Author: User
The previous article mentioned the implementation of the page number of the category page, but wordpress also provides the function of paging long articles. the implementation method is very simple: we know that wordpress has a more tag, there is a button in the background that can be inserted directly, but wordpress also has a & lt ;! -Nextpage-& gt; tag, which is displayed only when the corresponding button in the editor is not displayed. & lt ;! -Nextpage-& gt; yes

The previous article mentioned the implementation of the page number of the category page, but wordpress also provides the function of paging long articles. the implementation method is very simple: we know that wordpress has a more tag, there is a button in the background that can be inserted directly, but there is a button in wordpress Tag, but the corresponding button on the editor is not displayed, You can paging long articles. when editing an article, switch to html input, and enter

 

 

The usage of the more tag is the same. After the page number is added, we only need to output the content in the template: The page number function is added to the end of the function. However, this function can only display the page number, but cannot display the next page link of the previous page:

 

Wp_link_pages ();

?>

 

So we usually need to use this function three times to achieve the effect: "Previous Page 1 2 3 4 Next Page"

 

 

 

This is the most common requirement.

However, although the "previous page" and "next page" links can be displayed, there is also a fatal flaw. for example, when accessing the first page, the following page is displayed: 1 2 3 4 5 Next Page, that is, the "previous page" is not displayed, but there is still a connection "in the source code of the webpage, but there is no connection text. this defect makes the page number unable to achieve some results, for example, the figure in the previous article is similar to the following:

Because there is an empty label in front, when you add a border and background style to the label, the empty label in front will also display the style.

To solve this problem, had to view the function of this function source code, wp_link_pages function is located in wp-des/post-template.php file, looked at this function, the output does not provide the filter and action hook, so we have to modify the wp_link_pages () function. to avoid modifying the default files of wp, we can copy wp_link_pages () and paste it to functions. php file, and then change the name. for example, I changed the name to ashu_link_pages (). The new function is as follows. I commented on the modified part and can compare it:

 

 

 

Function ashu_link_pages ($ args = '') {$ defaults = array ('before' =>'

'. _ ('Pages:'), 'after' =>'

', 'Link _ before' => '', 'link _ 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); $ output. = $ link_before. $ j. $ link_after; // The original sentence below is moved into} else {// added an else statement to judge the current page. If yes, the following $ output is output. = ''. $ j. '';} // There is a sentence in the original, move it to the above if ($ I! = $ Page) | ((! $ More) & ($ page = 1) $ output. = '';} $ output. = $ after;} else {if ($ more) {$ output. = $ before; $ I = $ page-1; if ($ I & $ more & $ previouspagelink) {// $ previouspagelink is added to the condition in if, that is, $ output is displayed only when the parameter has the word "previous page. = _ wp_link_page ($ I); $ output. = $ link_before. $ previouspagelink. $ link_after. '';} $ I = $ page + 1; if ($ I <= $ numpages & $ more & $ nextpagelink) {// The condition in if is added with $ nextpagelink, that is, $ output is displayed only when the parameter has the "next page. = _ wp_link_page ($ I); $ output. = $ link_before. $ nextpagelink. $ link_after. '';} $ output. = $ after ;}}if ($ echo) echo $ output; return $ output ;}

This function can be used three times to implement various styles.

 

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.