作者页面上的评论分页

时间:2016-10-05 作者:mattkrupnik

我有个小问题,我有作者页面(example.com/author/joe) 在此页上I have listed all author comments with pagination 但单击url后分页不起作用-例如。com/author/joe/page/2,页面被重定向到索引。php。

在其他循环中,它可以工作,只是作者页面有问题。

有什么想法吗?

代码:

$paged = ( get_query_var( \'paged\' ) ) ? get_query_var( \'paged\' ) : 1;
$number = get_option(\'comments_per_page\');
$offset = ( $paged - 1 ) * $number;

$count = count( get_comments( array(
    \'user_id\' => $user_ID,
    \'status\' => \'approve\',
) ) );

$max_total = ceil($count/$number);

$args = array(
    \'user_id\' => $user_ID,
    \'number\' => $number,
    \'status\' => \'approve\',
    \'offset\' => $offset,
    \'paged\' => $paged
    );

$the_query = new WP_Comment_Query;
$comments = $the_query->query( $args );

foreach($comments as $comment){ 
 //code
}


//Pagination
$big = 999999999;

echo paginate_links( array(
    \'base\' => str_replace( $big, \'%#%\', esc_url( get_pagenum_link( $big ) ) ),
    \'format\' => \'?paged=%#%\',
    \'current\' => max( 1, get_query_var(\'paged\') ),
    \'total\' => $max_total,
    \'prev_next\'=> true,
) ); 

1 个回复
SO网友:luukvhoudt

确保已设置paged 查询中的参数,下面显示了如何执行此操作。

<?php
$paged = ( get_query_var( \'paged\' ) ) ? get_query_var( \'paged\' ) : 1;
$args = array(
     \'posts_per_page\' => 3,
     \'paged\' => $paged
); 
$the_query = new WP_Query( $args ); 
?>
有关分页的更多信息,请查看this page.