Simple and practical WordPress long article paging code

Source: Internet
Author: User

Recently, manyArticleDistribution, which is relatively long. This will lead to slow page loading, which is not conducive to the user experience. Especially for newly added WordPress theme pages, although there are not many texts, each WordPress theme must be accompanied by a small image to give readers a general understanding. To determine whether to perform the demonstration. The pages will be very long when nearly 30 WordPress Themes are added together. Therefore, you must find a methodPaging long articles.

I searched on Google and foundCodeThe solution is very good. It is valid after use in person, so I will share it here.

1. Add pagination button

If you are not in trouble, you can switch to the HTML mode when writing an article. Insert the following line of code without adding this line.PagingButton.

 
<P> <! -- Nextpage --> </P>

 

In fact, it is much easier to add paging buttons to the editor. I have seen this function through code modification before, but I forgot. Because I have been using the WordPress editor to enhance the plug-in: tinymce advanced. This button has long been available, and I will not talk about it here.

Add a paging button to the WordPress 3.4 text editor on

My fc.guansoft.com website, "if you are not the one, disturbing the female guests", also uses the paging code described in this article. But tinymce advanced plug-in is not installed on that site. So I found a simple method to add this paging button in the WordPress editor. The method is as follows:

Locate the/WP-nodes des/class-wp-editor.php file. Search 'Wp _ more ', Tag: (IN row 366)
 
1 $ Mce_buttons= Apply_filters ('Mce _ buttons ',Array('Bold ', 'italic', 'strikethangout', 'blockquote', 'bullist', 'numlist', 'blockquote', 'weight', 'justifyleft ', 'justifycenter', 'justifyright', 'callback', 'link', 'unlink', <span style = "text-Decoration: underline "> <strong> <span style =" color: # ff0000; text-Decoration: underline "> 'wp _ more ', </span> </strong> </span> 'signature', 'shellchecker ', 'fullscreen', 'wp _ adv '),$ Editor_id);

 

After 'wp _ more', add 'Wp _ page ', (Including single quotes and commas ). The modified code is as follows:
$ Mce_buttons= Apply_filters ('Mce _ buttons ',Array('Bold ', 'italic', 'strikethangout', 'blockquote', 'bullist', 'numlist', 'blockquote', 'weight', 'justifyleft ', 'justifycenter', 'justifyright', 'callback', 'link', 'unlink', <span style = "text-Decoration: underline "> <strong> <span style =" color: # ff0000; text-Decoration: underline "> 'wp _ more', 'wp _ page ', </span> </strong> </span> 'signature', 'shellchecker ', 'fullscreen', 'wp _ adv '),$ Editor_id);

 

In this case, you can view an icon similar to the more tag button in the text editor of the Background Article and edit the article page.

Similarly, a nextpage button appears in the code editor.

II, Add paging Function

WordPress actually comes with a paging function, but it is not called. Therefore, when editing an article, we insert a paging character without any changes. How can we call this function? The method is very simple. In the single. php file of the theme template, find the code similar to the following line.

 
<? PHP the_content ();?>

 

After this line of code, add the following code to implement the simple paging function.

 
<? PHP wp_link_pages ();?>

 

3. beautifying the paging Effect

After the two steps above, you can implement the paging function of long articles. But it is not so nice-looking. Let's beautify it to make the paging effect more perfect.

First, code the paging function in the previous step Replace with the following code.
 
<? PHP wp_link_pages (Array ('before' => '<Div class = "fenye"> paging:', 'after' => '', 'Next _ or_number '=> 'Next', 'previouspagelink' => 'previous page', 'nextpagelink '=> "");?> <? PHP wp_link_pages (Array ('before' => '', 'after' =>'', 'next _ or_number '=> 'number ', 'link _ before' => '<span>', 'link _ after' => '</span>');?> <? PHP wp_link_pages (Array ('before' => '', 'after' => '</div>', 'next _ or_number '=> 'Next ', 'previouspagelink '=> '', 'nextpagelink' =>" next page ");?>

 

 

Then, beautify the CSS style.

Directly put the following code at the end of the theme file style.css.

 /*  * Page paging *  */  . Fenye { Text-align : Center ; Margin : 0px auto 10px ; Font-weight : Bold } . Fenye Span { Background-color : # Dddddd ; Color : # Fff ; Font-weight : Bold ; Margin : 0px 1px ; Padding : 1px 6px ; Display : Inline-block ; Text-Decoration : None ; Border :1px solid # e0e0e0 ;} . Fenye { Text-Decoration : None ;} . Fenye a span { Background-color : # F6f6e8 ; Font-weight : Normal ; Color : #000 ; Text-Decoration : None ;}. Fenye A: hover Span { Background-color : # Dddddd ; Color : # Fff ;}

 

Shows the final display effect:

Iv. Solve the impact of repeated titles on Seo after pagination

The titles of these pages are the same because of the paging of long articles. I don't know if it will adversely affect Seo. Avoid it! You can add pages to WordPress articles to solve the problem of duplicate titles. We can change it to the following effect:

    • Simple and practical WordPress long article paging code-guan Shuo WordPress plug-in
    • Simple and practical WordPress long article paging code-2nd pages-guan Shuo WordPress plug-in
    • Simple and practical WordPress long article paging code-3rd pages-guan Shuo WordPress plug-in

Find the topic template file header. php similar to <title> ...... </Title> code, replace it with the following code.

<? PHPIf(Is_single () {?> <Title> <? PHPEcho Trim(Wp_title ('', 0);?> <? PHPIf(Get_query_var ('page ')){Echo'-Di ';EchoGet_query_var ('page ');Echo'Page';}?> -<? PHP bloginfo ('name');?> </Title> <? PHP }?>

 

5. Avoid paging the feed

After the paging function is implemented, the articles on the feed page are paginated. Generally, only the content on the first page is displayed.

Solution:

Open the query. php file under the WP-des directory and find the following line of code (about 3578 lines)

 
If(Strpos($ Content, '<! -Nextpage-> ')){

 

Modify it to the following line of code.

If(Strpos($ Content, '<! -- Nextpage --> ')&&(! Is_feed ())){

Source http://www.guansoft.com/simple-wordpress-page-long-articles-of-the-code.html

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.