Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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">
            <?php 

                foreach ($newcomments as $comment) :

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

Thanks

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

1 Answer

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

share|improve this answer
add comment

Your Answer

 
discard

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.