Having paged comments in WordPress


Warning: Use of undefined constant vs - assumed 'vs' (this will throw an Error in a future version of PHP) in /home/vssrvorg/public_html/wp-content/themes/vs-simplicity/single.php on line 38

Warning: Use of undefined constant simplicity - assumed 'simplicity' (this will throw an Error in a future version of PHP) in /home/vssrvorg/public_html/wp-content/themes/vs-simplicity/single.php on line 38

Warning: A non-numeric value encountered in /home/vssrvorg/public_html/wp-content/themes/vs-simplicity/single.php on line 38

Warning: A non-numeric value encountered in /home/vssrvorg/public_html/wp-content/themes/vs-simplicity/single.php on line 38

If you have a very popular blog it might be worth dividing your comments into pages for easier viewing. Fortunately there is a WordPress plugin called Paged Comments to do just that, thanks to Keyvan Minoukadeh. However it needs a bit of tweaking to work on your site.

Installing and configuring

  • Download and extract plugin files to a folder locally.
  • You can change the number of posts per page and some other useful settings by editing the paged-comments-config-sample.php file (its all fairly well explained in the file), then save the file as paged-comments-config.php.
  • Upload the whole paged-comments directory to /wp-content/plugins/ and enable the plugin through the WordPress admin interface.

Template hacking (yuck)

  • We need to include the comment ‘pager’ in our template. If you are using a common theme, it might already be taken care of: just go to /wp-content/plugins/paged-comments/themes, open your theme folder, and then copy the comments-paged.php file there into your theme folder at /wp-content/themes
  • If you are not using any of the themes listed in /wp-content/plugins/paged-comments/themes then go to your theme and copy the comments.php file to comments-paged.php

We will then modify the comments-paged.php as follows:

In the code at the start

<?php // Do not delete these lines
    if ('comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
        die ('Please do not load this page directly. Thanks!');

change comments.php to comments-paged.php

To add the pager, place this code

  <!-- Comment page numbers -->
<?php if ($paged_comments->pager->num_pages() > 1): ?>
 <p class="comment-page-numbers"><?php _e("Pages:"); ?> <?php paged_comments_print_pages(); ?></p>
 <?php endif; ?>
 <!-- End comment page numbers -->

before the <ol class="commentlist"> line and again after the </ol> marking the end of it

If you want to make comment number visible on the blog, add this line of code

<div class="comment-number"><?php echo $comment_number; $comment_number += $comment_delta;?></div>

You can add it anywhere between <?php foreach ($comments as $comment) : ?> and <?php endforeach; / end for each comment / ?>, but the best place is probably before the author name (<cite><?php comment_author_link() ?></cite>). In practice, this hasn’t worked too well for me, so use with caution.


Warning: Use of undefined constant vs - assumed 'vs' (this will throw an Error in a future version of PHP) in /home/vssrvorg/public_html/wp-content/themes/vs-simplicity/single.php on line 41

Warning: Use of undefined constant simplicity - assumed 'simplicity' (this will throw an Error in a future version of PHP) in /home/vssrvorg/public_html/wp-content/themes/vs-simplicity/single.php on line 41

Warning: A non-numeric value encountered in /home/vssrvorg/public_html/wp-content/themes/vs-simplicity/single.php on line 41

Warning: A non-numeric value encountered in /home/vssrvorg/public_html/wp-content/themes/vs-simplicity/single.php on line 41

Warning: count(): Parameter must be an array or an object that implements Countable in /home/vssrvorg/public_html/wp-content/themes/vs-simplicity/comments.php on line 33

Warning: count(): Parameter must be an array or an object that implements Countable in /home/vssrvorg/public_html/wp-content/themes/vs-simplicity/comments.php on line 34

Comments are closed.