Home>

Method description

Let's first look at the methods that may be used. Open the file wp-includes/link-template.php and you will find that wordpress 2.7 has 4 more methods for paginating comments:

get_comments_pagenum_link $pagenum:page number $max_page:maximum number of pages

Returns the link address. It will not be used in this application. But everyone should know that there is this method, Will make it easier for you to make plugins.

next_comments_link

$label:the typeface displayed, The default is»newer comments. But I always thought it was a bug, it should be newer comments»

$max_page:maximum number of pages

Displays a link to the next page.

previous_comments_link$label:the typeface displayed, The default is«older comments.

Shows the link to the previous page.

paginate_comments_links$args:string parameter group

-base:page url

-format:I don't know what it is. Can anyone tell me?

-total:maximum number of pages

-current:current page number

-echo:whether to show, The default is display. Returns the string html when not displayed.

-add_fragment:hash, default is #comments. For unity, Easy to understand, Also avoid modification, Suggested for the theme

Display the html of the comments tab or return to the comments tab.

Examples

Previous and next pageThis is the simplest, Also most often mentioned, The effect is no different from article pagination.

<div>
 <span>?php previous_comments_link (__ ("«older comments"))?></span>
 <span>?php next_comments_link (__ ("newer comments»"))?></span>
 <div></div>
</div>

2. Navigational Pagingmost transparent to visitors, The most convenient to use, The effect is similar to the effect of using wp-pagenavi paging.

<div>
 <?php paginate_comments_links ();?>
</div>

Take a look at the two previous examples, It seems that the functions we want can be achieved. But do n’t you think it ’s a bit weird?If you choose not to show the comments tab in the background, Or the number of comments is not enough to paginate, Do i want to show the frame too?No! We need to change this program.

You can get the background comment paging options by calling the method get_option ("page_comments").

We can also call the method paginate_comments_links ("echo=0") to know if the comments are sufficient and need to be paginated.

3. Previous and Next (Improved)

<?php
 //If the user chooses to display the comment tab in the background
 if (get_option ("page_comments")) {
 //Get the html of the comment pagination
 $comment_pages=paginate_comments_links ("echo=0");
 //If comment html is not empty, show previous and next links
 if ($comment_pages) {
?>
 <div>
 <span>?php previous_comments_link (__ ("«older comments"))?></span>
 <span>?php next_comments_link (__ ("newer comments»"))?></span>
 <div></div>
 </div>
<?php
 }
 }
?>

4. Navigational Paging (Improved)

<?php
 //If the user chooses to display the comment tab in the background
 if (get_option ("page_comments")) {
 //Get the html of the comment pagination
 $comment_pages=paginate_comments_links ("echo=0");
 //If comment html is not empty, display navigational pagination
 if ($comment_pages) {
?>
 <div>
 <?php echo $comment_pages;?>
 </div>
<?php
 }
 }
?>

For the latest comment paging feature, I have my own opinion, Just talk about it.

The comment pagination is not perfect. If a link outside jumps to http://www.example.com/#5630, but the comment number 5630 is not on the first page, Then you cannot locate this comment, The skipping brothers will feel more upset.

In addition, wordpress's comment pagination is not an ajax application (for browser compatibility, It is unlikely to be in the future), so page turning will be quite time consuming. So I recommend, Even if i want to paginate, Also make the number of comments displayed per page larger. 30?50?100?varies from blog to blog.

Alright, you probably already know how to use?css, I won't say much, Each is good, This is hard to say.

php
  • Previous Detailed transaction management methods in Java's Spring framework
  • Next Express implements front-end and back-end communication to upload pictures stored database (mysql) fool-style tutorial (1)