Compile a PHP script to implement the comment paging function in WordPress

Source: Internet
Author: User
This article mainly introduces how to compile a PHP script to implement the comment paging function in WordPress, including adding the next page on the previous page and navigation paging function. For more information, see Method description

First take a look at the methods that may be used. open the file wp-comments des/link-template.php you will find WordPress 2.7 4 more methods for pagination of comments:

  • Get_comments_pagenum_link
  • $ Pagenum: page number
  • $ Max_page: maximum number of pages

Return link address. this method will not be used in this application, but you should know that this method will make it easier for you to create a plug-in.

Next_comments_link

$ Label: the name displayed. the default value is» Newer Comments. but I always think this is a bug. it should be Newer Comments?

$ Max_page: maximum number of pages

The link to the next page is displayed.

Previous_comments_link
$ Label: the name displayed. the default value is "Older Comments.
Show jump
This is the simplest and most often mentioned, and the effect is no different from that of pagination.

<?php previous_comments_link(__('« Older Comments')) ?> <?php next_comments_link(__('Newer Comments »')) ?>

2. navigation paging
It is the most transparent to visitors and most convenient to use. The effect is similar to that of PageNavi pages.

<?php paginate_comments_links(); ?>

Let's look at the two examples above. it seems that all the functions we want can be implemented. But do you think it's a little strange? If you choose not to display the comment page on the background, or if the number of comments is not enough, do you want to display an external box with id = "commentnavi? No! We want to modify this program.
You can call get_option ('page _ comments ') to obtain the comment page option in the background.
We can also call the paginate_comments_links ('echo = 0') method to check whether the comment is sufficient and paging processing is required.

3. (improvement)

<? Php // if the user chooses to display the comment page in the background if (get_option ('page _ comments ')) {// Obtain the HTML $ comment_pages = paginate_comments_links ('echo = 0') of the comment page; // if the HTML of the comment page is not empty, the link displayed is if ($ comment_pages) {?>

<? Php previous_comments_link (_ ('«Older Comments')?> <? Php next_comments_link (_ ('newer Comments» ')?>

<? Php }}?>

4. navigation paging (improved)

<? Php // if the user chooses to display the comment page in the background if (get_option ('page _ comments ')) {// Obtain the HTML $ comment_pages = paginate_comments_links ('echo = 0') of the comment page; // if the HTML of the comment page is not empty, display the navigation page if ($ comment_pages) {?>

<? Php echo $ comment_pages;?>

<? Php }}?>

I have some opinions on the latest comment paging function.
The comment page is not perfect. if a link outside jumps to the http://www.example.com/#5630, but the comment numbered 5630 is not on the first page, then it cannot be located on this comment, the feeling of the brother who jumps will be more uncomfortable.
In addition, the comments pagination of WordPress is not an AJAX application (which is not likely to be used in the future for browser compatibility considerations), so page turning is quite time-consuming. therefore, I suggest that you set the number of comments displayed on each page to a large value even if you want to pagination. 30? 50? 100? It varies with domains.

Well, you probably know how to use it? CSS does not need to be said much. It has its own advantages. this is hard to say.

Related Article

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.