WordPress Paged Comments Plugin

This plugin is no longer being developed. WordPress has had paged comments support in the core since version 2.7. The comment paging you see here is using WordPress’s built-in code and not my plugin.

Paged Comments is a plugin for WordPress to allow comment paging. Useful for those popular blog entries receiving many comments, or a simple guestbook page within WordPress.

Features

  • Comment ordering: show latest comments first, or last
  • Specify number of comments to display per page
  • Enable paging for all posts and pages, or on a per-post basis
  • Give users the choice to view all comments on one page with a ‘show all’ link
  • Specify the first or last page of comments to load by default
  • See paged-comments-config-sample.php for more

Download — Latest Version

Installation (for WordPress 2.3 up to 2.7)

If you’re upgrading from a previous version, skip these installation steps and read the upgrade steps. Note: WordPress’ automatic upgrade feature will erase the plugin’s config file. If you’re going to use it, make sure you backup your paged-comments-config.php file first.

  1. Download and extract plugin files to a folder locally.
  2. Read through and edit paged-comments-config-sample.php to configure, then save the file as paged-comments-config.php.
  3. Upload the whole paged-comments directory to /wp-content/plugins/. The plugin files should now be in /wp-content/plugins/paged-comments/.
  4. Enable the plugin through the WordPress admin interface. That’s it!

Optional Steps

  • WP 2.7 users: If use_wp_config is set to true (default), you can make changes to the plugin config using the WP admin interface. Go to Settings > Discussion and look under ‘Other comment settings’.
  • To customise the template to work better with your theme: Open the plugin’s themes folder and find the subfolder corresponding to the WordPress theme you’d like paged comments enabled on (or if your theme isn’t listed, choose the ‘default’ folder). Upload comments-paged.php to the appropriate WordPress theme folder (found in [wordpress]/wp-content/themes/).

    For example, if you’re using the default WordPress theme, copy [paged-comments-plugin]/themes/default/comments-paged.php to [wordpress]/wp-content/themes/default/. (The plugin always tries to load comments-paged.php from your active theme folder first.)

    Make any modifications to comments-paged.php. The file is based on the comments.php file, so if your theme is very different it might be easier to copy in the necessary elements from paged-comments.php. View the diff report to see what you need to change.

Examples of Use

The comments on this page are handled by the plugin, but it’s also used by the following sites:

Questions?

Paid Support

If you run a commercial site and you’re having difficulty setting up paged comments, I offer paid support. Feel free to get in touch: keyvan (at) k1m.com

42 Comments

  1. Keyvan says:

    Tanster, here’s the fix for the comment number problem:

    Open paged-comments.php and find the following lines (should start from line 117) in the paged_comments_template() function:

    // comment numbering
    $comment_number = ...snipped...
    if ($paged_comments->ordering == 'DESC') {
        $comment_number += count($comments);
        $comment_delta = -1;
    } else {
        $comment_number += 1;
        $comment_delta = 1;
    }

    change to:

    // comment numbering
    $comment_number = ...snipped...
    if ($paged_comments->ordering == 'DESC') {
        $comment_mod = $comment_count % $paged_comments->pager->get_items_per_page();
        if ($paged_comments->fill_last_page && ($comment_mod != 0)) {
            $comment_number += $comment_mod;
        } else {
            $comment_number += count($comments);
        }
        $comment_delta = -1;
    } else {
        $comment_number += 1;
        $comment_delta = 1;
    }

    [Edited: 2006-02-17]

    That should do it. Let me know how you get on. I don’t have time to put out a new version yet, but the fix will be in the new version when it’s ready.

  2. tanster says:

    Hi Keyvan,

    The new code works BEAUTIFULLY! I have it running in my sandbox; as soon as it’s public, I will let you know.

    Thanks again for being so responsive!

    πŸ™‚ tanster

  3. Dayna says:

    Hi Keyvan,

    Is it all right for you to tell me how you achieve the permalinks to the comments with the paged comments?

    like

    http://keyvan.net/code/paged-comments/comment-page-11/#comment-1900

    instead of

    http://keyvan.net/code/paged-comments/#comment-1900

    Thanks πŸ™‚

  4. tanster says:

    Hi Keyvan,

    I see that paged comments uses comments-paged.php as its template, and if I click “Show All” then regular comments use whatever comments.php file is in my current theme.

    I am using a theme, however, which doesn’t number the comments.

    My question is: how do I get my standard comments.php file to display numbers in the comments just like comments-paged.php? (Just like it works here at http://keyvan.net/code/paged-comments/)

    Thanks!
    πŸ™‚ tanster

  5. Dayna says:

    tanster: I’m not sure if it’s the right way but this is how I do it

    add $commentcount=1;

    after $oddcomment = 'alt'; at the top of your comments.php

    and where you want the comment number to appear, use this

    echo $commentcount++;

    πŸ™‚

  6. Keyvan says:

    Dayna: If you’re using one of the bundled templates, you should have a call to this function within the comment loop:

    echo paged_comments_url('comment-'.get_comment_ID());

    The function returns the ‘permalink’ URL of a comment—it’s not perfect and I’m working on a better solution for a future release. The function will also take into consideration the current comment page. So, for example, when you load this page the last comment-page is active (at the moment page 11) but the page URL doesn’t contain the /comment-page-11/ path segement. So returning ‘#comment-1911’ is not enough as someone might link to, like in your example, http://keyvan.net/code/paged-comments/#comment-1911 (which is only valid while comment page 11 is being loaded by default). So paged_comments_url will (at least it does for me :)) return http://keyvan.net/code/paged-comments/comment-page-11/#comment-1911.

    Please check and let me know if paged_comments_url() is being used in your comments-paged.php template. If it’s not working right I’ll have to look into it some more.

    I mentioned above that I’m working on a better solution that will—if I implement it correctly :)—produce URLs with no reference to the comment page, somethine like: http://keyvan.net/code/paged-comments/comment-1911/.
    I’m hoping the code can then look at the paged-comments configuration to figure out, and redirect to, the correct comment page. (Not even sure if this is the ideal solution yet!) πŸ™‚

    Tanster: I’m not too happy with the way it works at the moment (ie. having to maintain two comment templates). If you’re only after the comment numbers, you can do what Dayna suggested.

    The next version will always use the comments-paged.php template while the plugin is active within WordPress. (Deactivating will revert back to comments.php.) I’m actually using the development version on this site, which only uses comments-paged.php (so when you choose ‘show all’ you’re still getting comments-paged.php). If you’re brave enough, you can load it and try it: paged-comments.php. You don’t need to make changes to your config file, but there is a new option available:

    // Show-all comment ordering
    // -------------------------
    // Determines how comments are ordered when loaded on a single page.
    // The default ascending ('ASC') order means comments will be ordered with
    // the earliest comment displayed first. 'DESC' reverses this order. 
    // The ordering specified here is used in the following circumstances:
    // 1. When a user chooses the 'Show All' option to have all comments displayed at once.
    // 2. When the total number of comments has not exceeded the per_page value (ie. when 
    //    they're few enough to fit on a single comment page).
    // In all other circumstances, the value specified in ordering is used.
    $paged_comments->show_all_ordering = 'ASC';

    Hope that helps.

  7. tanster says:

    Dayna: Thank you, that works like a charm!

    Keyvan: Thanks for the updated paged-comments.php; I’m not brave enough to use it, though! πŸ˜‰

    Also, looks like I spoke too soon about the numbering working correctly in fill_last_page mode:

    Up to 19 comments, it works fine:
    – Page 2, 10 comments numbered “19” through “10”
    – Page 1, 9 comments numbered “9” through “1”

    Once I have 20 comments, this is what I see:
    – Page 2, 10 comments numbered “10” through “1” (should be “20” through “11”)
    – Page 1, 10 comments numbered “0” through “-9” (should be “10” through “1”)

    My settings:
    – all_posts = true;
    – per_page = 10;
    – ordering = ‘DESC’;
    – page_range = 5;
    – fancy_url = false;
    – show_all_option = true;
    – fill_last_page = true;

    Thanks!
    πŸ™‚ Jennie

  8. Keyvan says:

    Hi Tanster,
    Sorry about that. Even the most basic maths still trips me up. πŸ™‚ I’ve corrected the code I posted earlier. Please try it and let me know if it works. (It’s looking quite ugly now—I’m sure there’s a very elegant mathematical solution out there somewhere!)

  9. tanster says:

    That fixed it, Keyvan. Once again, thank you!

    πŸ™‚ tanster

  10. tanster says:

    Okay, paged comments are now functional on my site:

    http://www.officetally.com/?p=35#comments

    The theme being used is a modified version of the “Neat!” theme at http://www.aamukaste.org/wpthemes/?cat=3

    πŸ™‚ tanster

  11. Dayna says:

    Keyvan: Thanks, it’s working now. πŸ™‚ Good luck in the new version. And a question regarding the new version, you mentioned to use the comments-paged.php whenever the plugin is activated. So what if I only want paged comments for my pages and not posts?

  12. Keyvan says:

    Tanster: Nice site! Glad the plugin’s finally working okay. πŸ™‚

    Dayna: Glad it’s working. Just curious, was it the URL function I mentioned, or something else?

    Regarding the template file and paging. I’m still going to add your suggestion of an option to restrict paging to posts or pages. The idea behind using a single comments template is to make maintenance of the template file easier. The way the plugin works at the moment means users have to maintain two comment templates (comments.php and comments-paged.php). So to get a consistent theme you end up having to duplicate any template changes you make in one template to the other.

    When I say the plugin will always use comments-paged.php in a future version, I don’t mean it’ll force paging. Just that while the plugin is active you’ll only have to worry about the one template—so, as before, you’ll still see all comments on a single page if paging isn’t enabled. I hope that makes sense. I think I’ve confused myself talking about it! (And having a template called comments-paged.php will probably cause even more confusion when this change comes into effect!) πŸ™‚ I’m open to suggestions though. If you think this is bad idea, or if you can think of something better, let me know.

  13. tanster says:

    Thanks Keyvan! I’m really happy with how it turned out.

    πŸ™‚ tanster

  14. Dayna says:

    Yup, it was the one with the

    /comment-page-1/#comment-687

    Right, I like that idea I think it would be rather convienient as well. πŸ™‚

  15. Jonathan says:

    Thanks for updating the plugin to support WordPress 2 fully.

    I have one slight issue with the fancy URL feature which caused issues with a non-wordpress part of my site (and which I can see interfering with other plugins).

    The first line of your code strips off the trailing “/” if there is one. This is then written back to the variable $_SERVER[‘REQUEST_URI’] even if the page in question is not a comments page, or indeed even if it’s not a WordPress page.

    I’ve changed your code so that $_SERVER[‘REQUEST_URI’] = $req; is inside each of the “if” statements, so that the URI is untouched if it doesn’t refer to a comments page.

    (Part of my site checked for a trailing “/” and added it if it wasn’t there. So I had an infinite loop! I know there’s a plugin that does this for WordPress pages too!)

  16. Keyvan says:

    Thanks Jonathan. I should be more careful tampering with these things. I’ll try and put out a new release tonight with this change. Hope it didn’t waste too much of your time pinning the problem down (I know these infinite loops can be a bit of nightmare to resolve). Thanks for letting me know.

  17. Jonathan says:

    Not at all, Keyvan, you’ve already implemented the “Comment awaiting moderation” feature I suggested a while ago; and from your code, I now understand how WordPress 2 handles permalinks! I actually tracked down the looping redirects quite quickly (which is unusual for me!) after I noticed the 301s in the access log! For normal WordPress pages it shouldn’t matter as they don’t care about the “/”. I just want all my pages indexed with it there for consistency!

  18. Keyvan says:

    New bug-fix release is now available for download. Fixes the trailing slash issue and the comment numbering issue when DESC and fill_last_page are both enabled. Thanks to Jonathan and Tanster. No new features introduced in this release, but I recommend you upgrade. (Which just involves replacing paged-comments.php if you’ve already got your paged-comments-config file in place.)

  19. […] The basic idea has been borrowed (along with a few lines of code) from Keyvan’s Paged Comments Plugin, but the configurability through the theme’s options page and especially the complete AJAX functionality has been handcoded from scratch. Especially the inability of prototype.js to handle responseXML has cost me several years of my future live, I fear […]

  20. Keyvan – thanks for a very useful plug-in! It’s exactly what I needed to speed up loading on my popular pages.

    Mike

  21. pavel.nesvadba says:

    Hi Keyvan, I have almost 500 comments in some posts on my blog and then you plugin is very intersted for me. Thanks for it.

    But … I have one problem. I want to preset comments ordering to ASC mode with 50 comments per page. But after it when I click on some post with around 500 comments I see comments 1-50 … so 50 oldest comments. But I want see 50 latest comments on first page …

    Can I do it someway ??

  22. Keyvan says:

    Pavel, to see the latest comments you will have to set ordering to DESC. If you want the 50 latest comments to always be shown on the default page, you will also have to enable the fill_last_page option. I hope I’ve understood your question. If not, please post back.

  23. pavel.nesvadba says:

    Hi Keyvan … thanks for replay, but it is not exactly what I want …

    I want comments ordering in ARC mode and latest comments on the default page …

    for example: I have 421 comments, with 50 comments per page … then, I would like to display comments 371 – 421 on default page therewith that comment 371 would be on the top of the page and comment 421 on the bottom.

  24. Keyvan says:

    Hi Pavel, I understand now. There’s no option to enable this behaviour at the moment. If I get some time tomorrow I’ll post up a quick hack to allow you to do it.

  25. pavel.nesvadba says:

    Keyvan: thanks In Advance πŸ™‚

  26. prem says:

    Need some help. I am using the paged-comments.. nice plugin.

    But other than the first page, ie when someone clicks on the other numbered comments pages I want to display just the comments not the complete posts. Can someone tell me how to do that.

    Basically for comment pages 2 onwards I do no want to see the post on those pages.. just the comments. I fear that on every page if we have the post displayed search engines will treat them as duplicate pages as content will be very similar.

    Thanks.. pls reply here..

  27. Keyvan says:

    prem: This is covered in the FAQ.

    Pavel: I’m sorry, I haven’t had time yet. I’ll let you know when I’ve posted up a solution.

  28. pavel.nesvadba says:

    Keyvan: ok … πŸ™‚

  29. […] Das ist ein Punkt über den ich mir eine Menge Gedanken gemacht habe. Wie sortiert man die Kommentare? Zuerst den ältesten oder zu erst den, der als letztes geschrieben wurde, also noch am neuesten ist? Schwierige Frage, im Moment bin ich dabei es eher konventionell zu halten also geordnet von alt zu neu. Diesbezüglich vertraue ich auf euer konstruktives Feedback, da es für mich da keine 100%-ige Antwort in eine Richtung gibt. Bei dem Punkt Sortierung der Kommentare geht es mir noch um etwas anderes. Ich denke jeder hat es schonmal erlebt, dass Beiträge zu denen eine Menge Kommentare abgegeben wurden eine halbe Ewigkeit laden. Das ist natürlich nicht gerade angenehm für die Blogleser. Dafür hab ich jetzt ein WordPressplugin gefunden, dass die Kommentare in mehrere Unterseiten aufteilt. Paged-Comments heißt das ganze und verbessert die Ladezeiten erheblich. Bei mir sind mir die Ladezeiten bisher nicht negativ aufgefallen also ist der Einsatz nicht unbedingt Pflicht. Wenn einem etwas negativ auffällt bitte ich wie immer um eine Meldung, danke. […]

  30. […] I’m going to install the WordPress Paged Comments plugin, found at Keyvan’s excellent site. // Individual posts can still enable paged comments by adding a custom // field: ‘paged_comments’ with the value ‘on’. […]

  31. pavel.nesvadba says:

    Keyvan don’t forget for me please πŸ™‚

  32. Keyvan says:

    Pavel, you haven’t been forgotten. I’ve just been too busy to work on the plugin. I will show you how to do it when I get a little more time.

  33. […] Da meine Kommentar Liste im Gästebuch langsam länger wird, habe ich nach einer Möglichkeit gesucht dies auf mehrere Seiten zu verteilen. Durch WordPress.de bin ich auf das Paged Comments Plugin gestoßen. Ich habs gleich runtergeladen, die paged-comments.php angepasst und das Plugin installiert. Ich muss mal noch kucken wie ich die “Kommentarnummer” im Kommentar selbst angezeigt bekomme. […]

  34. Stolon says:

    Wery good plugin! Thanks!

  35. […] So I redesigned my main blog with the wonderfull Hemingway theme. I stopped using comments on a per post basis, I find comments to often non-topic. Instead I created a guestbook using the paged comments plugin and some template advise from Jennifer. Posted by woordenaar Filed in WordPress […]

  36. Keyvan says:

    Pavel: The new version is available now and it includes a new option (default_page) which does what you want. Sorry it took so long. You can see it in action (I’ve set ordering to ‘ASC’ and default_page to ‘last’).

    Read about the other changes.

    Let me know if you come across any problems.

  37. […] Nyt on Lammikon merkint?jen kommentteihin asennettu sivutus-plugin pakon sanelemista syist?. Nuo er??t pirulaiset (1 ja 2) alkoivat nimitt?in n?ytt?? jo melko runsailta. […]

  38. Dayna says:

    Hi, I have got the new version but there is a problem with the fancy URL again, the link to other comments pages are the default permalink and not the custom permalink of the page. Can you fix that please? Thank you πŸ™‚

  39. Dayna says:

    Edit: Sorry, I didn’t realise there’s a new config for fancy URL. Could I suggest a admin options page? The current config seems a bit messy and confusing. Just a suggestion πŸ™‚ Thank you for the update

  40. Keyvan says:

    Hey Dayna, not sure what problems you’re having with the fancy URL option – the new options shouldn’t affect the URL structure. Have I broken something?

    Thanks also for the suggestion. I’d like to do an options page accessible through the WP admin interface. It’d probably make updates easier as well. I’ll consider it for the next release.

  41. Dayna says:

    Hi Keyvan, it was my mistake. I’m sorry because there are too many configuration in the file that I missed out that option to set fancy URL to true. Thank you for considering that suggestion as well. It would make setting the configuration so much easier. πŸ™‚

  42. Gray Charles says:

    Keyvan,

    My readers are requesting the following: If I’m on page “n” of a multi-paged comments post and I post a new comment – the resulting page displayed is now the first page – not page “n”. Is there any way to keep it on page “n”?

  43. Keyvan says:

    Hi Gray, I’ll look into this to see what can be done. Although I think most people when posting a comment will have finished reading and would actually want to be redirected to the page their comment appears on—to see if it actually went through, if it appears okay, etc.

  44. pavel.nesvadba says:

    Keyvan: Wow … thanks … I will try it …

  45. pavel.nesvadba says:

    So … I tried new version with “default page” function … it works superbly but there is once more setting which I would like to set on my blog and I think there is no options for it.

    I have “last Default page” and “ASC Comment ordering” … and I want that the last comment-page contain the maximum number of comments anyhow works Fill last comment-page in descending (DESC) mode. There is some alternative for this setup ?

  46. Keyvan says:

    Pavel, good point. I’ll try and add this to the next version.

  47. Snoogly says:

    How can I make the ‘leave a reply’ block appear on it’s own page – and then have a link to the paged comments themselves?

    I am trying to make a very compact site.

  48. pete watch says:

    Great Plugin! Really nice work, thank you for this one!:)

  49. […] I just added few minor plugins for commenting section of the blog.Β  I didn’t really want to bother at first but after reading some LiveJournal entries, I figured it’s worth the time. This is the modified version of Brian’s Threaded Comments and Paged Comments plugin which merges these two. […]

  50. […] Paged comments here at katesgasis.com is powered by Keyvan Paged Comments Plugin. […]

8 Trackbacks

  1. […] The basic idea has been borrowed (along with a few lines of code) from Keyvan’s Paged Comments Plugin, but the configurability through the theme’s options page and especially the complete AJAX functionality has been handcoded from scratch. Especially the inability of prototype.js to handle responseXML has cost me several years of my future live, I fear […]

  2. By kk-works.de » Blogdesign Tipps #3 on 12 March 2006 at 3:32 pm

    […] Das ist ein Punkt über den ich mir eine Menge Gedanken gemacht habe. Wie sortiert man die Kommentare? Zuerst den ältesten oder zu erst den, der als letztes geschrieben wurde, also noch am neuesten ist? Schwierige Frage, im Moment bin ich dabei es eher konventionell zu halten also geordnet von alt zu neu. Diesbezüglich vertraue ich auf euer konstruktives Feedback, da es für mich da keine 100%-ige Antwort in eine Richtung gibt. Bei dem Punkt Sortierung der Kommentare geht es mir noch um etwas anderes. Ich denke jeder hat es schonmal erlebt, dass Beiträge zu denen eine Menge Kommentare abgegeben wurden eine halbe Ewigkeit laden. Das ist natürlich nicht gerade angenehm für die Blogleser. Dafür hab ich jetzt ein WordPressplugin gefunden, dass die Kommentare in mehrere Unterseiten aufteilt. Paged-Comments heißt das ganze und verbessert die Ladezeiten erheblich. Bei mir sind mir die Ladezeiten bisher nicht negativ aufgefallen also ist der Einsatz nicht unbedingt Pflicht. Wenn einem etwas negativ auffällt bitte ich wie immer um eine Meldung, danke. […]

  3. By WordPress Custom Fields and Keys at Elliot Lee on 20 March 2006 at 12:59 am

    […] I’m going to install the WordPress Paged Comments plugin, found at Keyvan’s excellent site. // Individual posts can still enable paged comments by adding a custom // field: ‘paged_comments’ with the value ‘on’. […]

  4. […] Da meine Kommentar Liste im Gästebuch langsam länger wird, habe ich nach einer Möglichkeit gesucht dies auf mehrere Seiten zu verteilen. Durch WordPress.de bin ich auf das Paged Comments Plugin gestoßen. Ich habs gleich runtergeladen, die paged-comments.php angepasst und das Plugin installiert. Ich muss mal noch kucken wie ich die “Kommentarnummer” im Kommentar selbst angezeigt bekomme. […]

  5. […] So I redesigned my main blog with the wonderfull Hemingway theme. I stopped using comments on a per post basis, I find comments to often non-topic. Instead I created a guestbook using the paged comments plugin and some template advise from Jennifer. Posted by woordenaar Filed in WordPress […]

  6. By Lammikko :: Blogi » Sivutus-plugin on 8 April 2006 at 8:19 am

    […] Nyt on Lammikon merkint?jen kommentteihin asennettu sivutus-plugin pakon sanelemista syist?. Nuo er??t pirulaiset (1 ja 2) alkoivat nimitt?in n?ytt?? jo melko runsailta. […]

  7. […] I just added few minor plugins for commenting section of the blog.Β  I didn’t really want to bother at first but after reading some LiveJournal entries, I figured it’s worth the time. This is the modified version of Brian’s Threaded Comments and Paged Comments plugin which merges these two. […]

  8. By katesgasis.com Paged Comments on 4 May 2006 at 4:05 am

    […] Paged comments here at katesgasis.com is powered by Keyvan Paged Comments Plugin. […]