PAIN. Comments Pagination

Sorry for flame, but i wasted 7-12 hours trying to understand how comments pagination works....Never thought that simpl

Sorry for flame, but i wasted 7-12 hours trying to understand how comments pagination works.... Never thought that simple step will take that much with WordPress :'((((

i output comments in my theme like this:

wp_list_comments(
      array(
         'callback' => 'regular_comment',
         'avatar_size' => 100,
         'style'       => 'ol',
         'short_ping'  => true,
         'reply_text'  => __( 'Reply', 'twentyseventeen' ) . ' ' . '<img class="comments-icon" src="' . get_path() . '/assets/i/others/chat.svg">',
           )
      );

And trying to use

echo paginate_comments_links();

for outputting pagination. Now after many hours of trying i understood that there is no way to use paginated comments unless you select that option in admin under Settings->Discussion.....

set_option('page_comments');

If that option is not set - no matter how hard i try to get total comments and set 'per_page' arg for wp_list_comments() - pagination urls ({N}/#comments simply won't work - url just redicts to

So, i have to setup that option... but. If you let's say want on one page to show 5 comments per page and 10 on another, then you use 'per_page' for wp_list_comments(), right ?

wp_list_comments( ...args, 'per_page' => 5)

while in admin panel we have let's say 10. After setting this up we need to tell paginate_comments_links() total number of comments on pages, because otherwise it will count using values provided in admin settings(under Settings->Discussion) So,

paginate_comments_links( array( 'total' => count_number_some_way ) )

In this case we will get pagination numbers as we want, but pagination will only work for pages defined in admin panel.... comments now show up on page according to 'per_page' argument for wp_list_comments, but pagination still works only for values in admin panel... It does show different number of pages. For example, we have 12 total comments on post, defined 6 per page in admin panel and now want to display 2 per page via 'per_page' argument, so pagination number will increase from 1..2 to 1..2..3..4..5..6. But only 1..2 will work, other links will just output no comments...

Solution. I've solved this by using get_comments() with 'number' and 'offset' arguments.

You will need to count comments by wp_count_comments( post_id )->approved, then output pagination using any suitable for you pagination function. And last but not least disable redirection for this particular post_type to make get_query_var($paged) functionality work

When using get_comments function you get full controll for quering comments, since it's a function that utilizes WP_Comment_Query Class. You can ASC DESC comments in any way you want, query with different parametrs, etc.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742286450a4415408.html

相关推荐

  • PAIN. Comments Pagination

    Sorry for flame, but i wasted 7-12 hours trying to understand how comments pagination works....Never thought that simpl

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信