WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am hoping someone can help me with comments pagination. I have the pagination working and the links point to the next page etc, but when clicking the page just refreshes. Here is my code so far and hoping someone can help me.

$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">

                foreach ($newcomments as $comment) :

full code: http://pastebin.com/md3zdpbd


share|improve this question
I added the formatting, but please care about the code style. Thanks. – kaiser Jan 8 '12 at 5:40

There's an easy function a.k.a. template tag for that called paginate_comments_links()

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.