最有可能的是,您遗漏的主要内容是您必须在Settings Discussion Subpanel. 分页函数要求设置这一点,URL重写也是如此。
下面是一个工作完整的页面模板,可以满足您的要求:
<?php
/*
Template Name: All Comments
See http://wordpress.stackexchange.com/questions/63770/aggregate-comments-with-pagination
*/
get_header(); ?>
<div id="content" role="main">
<?php
# The comment functions use the query var \'cpage\', so we\'ll ensure that\'s set
$page = intval( get_query_var( \'cpage\' ) );
if ( 0 == $page ) {
$page = 1;
set_query_var( \'cpage\', $page );
}
# We\'ll do 10 comments per page...
# Note that the \'page_comments\' option in /wp-admin/options-discussion.php must be checked
$comments_per_page = 10;
$comments = get_comments( array( \'status\' => \'approve\' ) );
?>
<ol start="<?php echo $comments_per_page * $page - $comments_per_page + 1 ?>">
<?php wp_list_comments( array (
\'style\' => \'ol\',
\'per_page\' => $comments_per_page,
\'page\' => $page,
\'reverse_top_level\' => false
), $comments ); ?>
</ol>
<?php # Now you can either use paginate_comments_links ... ?>
<?php paginate_comments_links() ?>
<?php # Or you can next/prev yourself... ?>
<?php if ( get_comment_pages_count( $comments, $comments_per_page ) > 1 ) : // are there comments to navigate through ?>
<nav id="comment-nav">
<div class="nav-previous"><?php previous_comments_link( __( \'← Newer Comments\' ) ); ?></div>
<div class="nav-next"><?php next_comments_link( __( \'Older Comments →\' ) ); ?></div>
</nav>
<?php endif; ?>
</div><!-- #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
如果您不想全局启用注释分页,这仍然是可能的,但这是一个小问题,因为您必须手动添加重写规则。一旦你这么做了,你就可以骗WordPress认为注释分页是通过一个简单的过滤器启用的,
add_filter( \'pre_option_page_comments\', \'__return_true\' );