Comment Pagination

时间:2012-01-07 作者:Shannon Hyland

我希望有人能帮助我的评论分页。我有分页工作和链接指向下一页等,但当点击页面只是刷新。这是我目前的代码,希望有人能帮助我。

$pid = $post->ID;   
$comment_query = "SELECT * FROM `wp_comments` WHERE comment_post_ID = ".$pid. " AND comment_approved = \'1\'";
$comments_array = $wpdb->get_results($comment_query, OBJECT);

if ($comments_array): 
                                                $cpp = 10; // Comments per page
                                                 $wp_query->comments = count($comments_array);
                                                 //echo $wp_query->found_posts;
                                                 $wp_query->max_num_pages = ceil($wp_query->comments / $cpp);
                                                 $on_page = intval(get_query_var(\'paged\'));
                                                 if($on_page == 0){ $on_page = 1; } 
                                                 $offset = ($on_page-1) * $cpp;
                                                 $wp_query->request = "
                                                SELECT * FROM `wp_comments` WHERE comment_post_ID = ".$pid. " AND comment_approved = \'1\'                                            
                                                LIMIT $cpp
                                                OFFSET $offset
                                                    ";
                                                $newcomments = $wpdb->get_results($wp_query->request, OBJECT);
?>                                      
<div class="comments">
    <?php if ($newcomments) : ?>
        <a name="comments" id="comment_anchor"></a>
        <h3 class="section-title"><?php _(comments_number(\'No <span>Comments</span>\',\'1 <span>Comment</span>\',\'% <span>Comments</span>\')); ?></h3>
        <ul class="comment-container">
            <?php 

                foreach ($newcomments as $comment) :
完整代码:http://pastebin.com/md3zdpbd

谢谢

1 个回复
SO网友:kaiser

有一个简单的函数a.k.a.模板标记paginate_comments_links()

结束

相关推荐

Comments and pingbacks issues

我已经想了很多很多天了。我多次尝试修改代码,总是得到相同的结果。我就是不明白。我想正确地分离pingback和注释,这是我使用以下代码所做的:<?php if ( have_comments() ) : ?> <h2 class=\"h2comments\"><img src=\"http://zoomingjapan.com/wp-content/themes/alltuts-child/images/comments_big.png\" /><