WordPress Plugin: Smart Unread Comments

As seen on Webfroot and this site, now in WordPress Plugin form!

Current Version: 1.3

What it does
Creates a list of posts with comments that haven’t been read by the user since their last visit/session. Uses cookies to track users last visit – no database required!

How it works:
Users are issued cookies which are used to track last visit. If this is their first visit, all comments in the last 14 days are unread. The plugin generates a list of unread comments. It keeps track of the user’s read posts for the session, removing them from the list as the user goes. Each page load updates the last unread timestamp cookie. Users can also mark all comments as read.

Installation:
Either:

Implementation:
In your template, add this code.

<ul><?php echo get_smart_unread_comments(); ?></ul>

get_smart_unread_comments() also takes options:

  • $limit
    Default: 5.
    Maximum posts with unread comments to display.
  • $output_when_no_unread_comments
    Default: TRUE
    If true, when there are no unread comments, it will output a <li class="wbftSUC_NoComments" > item containing $no_unread_comments_text
  • $output_when_more_unread_comments_than_limit
    Default: TRUE
    If true, when there are more than $limit unread comments, it will output a <li class="wbftSUC_MoreComments" > item containing $more_unread_comments_text
  • $mark_comments_as_read_text
    Default: “Mark all comments as read”
    String used in link Mark all Comments as Read link.
  • $no_unread_comments_text
    Default: “There are no unread comments”
    String used when there no unread comments and $output_when_no_unread_comments is TRUE
  • $more_unread_comments_text
    Default: “There are %d more unread comments…”
    String used when there are more than $limit unread comments and $output_when_more_unread_comments_than_limit is TRUE
    %d will be replaced with a count of how many more comments there are to view.

Documentation:
You’re looking at it!

CSS Classes output:
Remember, CSS classes are CASE SENSITIVE.

  • class='wbftSUC_MarkAsRead'
    Used on the Mark Comments as Unread link
  • class='wbftSUC_Recent'
    Used on comments less than 6 hours old
  • class='wbftSUC_MoreComments'
    Used on More Unread Comments list item
  • class='wbftSUC_NoComments'
    Used on No Unread Comments list item

Version History:
1.3: Now uses permalink structure, and sets cookies to your blog’s path. $limit defaults to 5 (not 10), and $output_when_more_unread_comments_than_limit defaults to TRUE.
1.21: Fixed broken (x)html validation due to stray
1.2: Fixed major bug with post title links.
1.11: Tables are now pulled from WP variables.
1.1: Initial Public Release.

Known Issues:
Comments on Pages (as opposed to posts) turn up on the list, but visiting the Page doesn’t mark those comments as unread.

Credit:

  • Chris Beaven (aka SmileyChris) for writing the original code seen on Webfroot, and helping with updating it.
  • Dan aka Mufasa and Tom for isolating the code from Chris’s Webfroot code magic and encouraging Me to write it.
  • Brett Taylor (Me! aka Glutnix) for turning it into a WP plugin and making the number of unread comments on each post link to the oldest unread comment rather than the newest unread comment.

Bugs and Suggestions
Any bugs or suggestions, please email me – email link in the sidebar (RSS readers: drop by the site ;) ).

62 thoughts on “WordPress Plugin: Smart Unread Comments

  1. […] gs   Even better than the Smart Unread Comments functionality on Webfroot! Smart Unread Comments displays a list of posts with comments unr […]

  2. Hi,

    This seems pretty good, but it breaks if the table prefix in the DB is anything other than “wp_” (because it’s hardcoded).

    I think you want to get hold of $table_prefix somehow, but I’m not altogether sure how.

    Cheers,

    Carl

  3. It seems there is another bug. The cookies do not register on WP 1.5 Pages.

  4. Comment!

  5. For some reason, the /?posts_timeout=1 link just returns a blank page and doesn’t mark all comments as read? Any ideas?

  6. Ken

    Hi Brett, since this plugin doesn’t work with permalinks, is there a fix in the works, or can you provide me instructions on what I need to modify to make it work?

  7. Yes, it’s a known issue that the plugin doesn’t use your permalink structure. Even so, it should still work, as it works here on inner.geek and on Webfroot.

    I haven’t looked into how to fix it — is there a function that will generate the permalink from a post_id?

  8. Ken

    Right now, whenever I click on one of my links for unread comments, it takes me to my root index page. Hmm. Sorry, don’t know about the function you’re looking for. I’m still fairly new to this.

  9. I had to go through your code and change every instance of

    href="/

    to

    href="/blogs/pt/

    to make it work with my blog (because the root of my blog isn’t /).

  10. Looks like someone messed up the description for your plugin on
    http://codex.wordpress.org/Plugins/Comments

  11. Brak

    Hey Brett, I’m not sure the $output_when_more_unread_comments_than_limit option works. Or rather, I don’t think it’s working for me. It seems to just follow whatever $limit is. If I set $limit to 15, clear my cache and reload, I get 15 comments and $more_unread_comments_text says that there are 15 more unread comments. If I change $limit to 14, it displays 14 comments & says I have 14 more unread, etc.

    Oh, and not to start off w/ something negative. I love the plugin. Great job. I’m just wondering if you know what’s going on there, if that’s expected, or what.

  12. […] t whatever you find most useful at the top. Search upfront, then one of the new features, Unread Comments. This will allow you to, at a glance, see if the […]

  13. Brett, I’m curious if you’ve taken a look at making different links for Pages that get comments. When a page with a comment gets listed in the plugin, i get a link that looks like this
    \?p=77277879&c=1
    and then when clicking it, I get “no posts matched your criteria”

    I was thinking of taking a look at the posts table to see how to go about segregating Pages out of the results. I personally want them to be listed but I can also see how others may not.

  14. […] tus field called “Show on front page” which will be checked by default for all posts. Smart Unread Comments Creates a list of posts wi […]

  15. zz85: yeah, it’s a known issue. Will resolve it when I get some time to nut out why it’s treating pages differently.

  16. […] tch” Another “must have” cool plugin. It has just been updated to v1.3 http://inner.geek.nz/archives/2005/02/11/wordpress-plugin-smart-unread-comments/ 2 Issues I faced. Doesnt work with pages Almost destroy the layo […]

  17. Just another bug I noticed (maybe only for me :() is that the I keep seeing “There are 1 more unread comments…” when there are actually more than that. So after clicking on one unread comment, then will i see another 1 unread comment appearing.

    after removeing /* */ around is_page(), the page comments get removed but only after 1 more extra page load. Using “Mark all comments as read” works well.

  18. […] and I had to change it to the Most Wanted plugin. Another plugin that I activated is the Smart Unread Comments which allows my readers to […]

  19. Whenever I’m on one of my pages (like my about me page) it shows comments that I’ve already read, and clicking on the “mark comments as read” link doesn’t seem to do anything. I thought it might have been a known issue, but when I tried it here on your site it worked fine. Actually, even after reading the comments, going back to the index it still shows them as read, I have to manually mark them as read. Did I goof up somewhere, somehow?

  20. Ok, I fixed the link not doing anything problem. Like someone else mentioned, my blog isn’t in the root either, it’s in /blog/ so I just had to add the / in the url for the mark comments read link, seems to have fixed that part. 😀

  21. […] cevoir les mise à jour par courriel, vous ne les verriez pas. Alors j’ai ajouté un plugin qui affiche les derniers commentaires que vous n’av […]

  22. […] Blog Archive » WordPress Plugin: Smart Unread Comments Published 0 minutes ago inner.geek » Blog Archive » WordPress Plugin: Smart Unread Comment […]

  23. Maybe it’s some kind of issue, but when I modify the plugin to show the 3 last comments to show it displays 4, when I do it for 4 it displays 5 … is that normal?

  24. This seems to be a nice plugin. The idea is good… it would be nice to have this integrated in the admin panel, however.

  25. Great plugin. Tons of help.

    The SQL queries broke for me on custom 404 pages, so I added a check for !$postid on lines 45 & 71.

    Couldn’t hurt to throw it in — or if anyone else has that problem.

  26. FogCat

    I’ve added this plugin to my daughters blog and it works as expected with IE – but Firefox doesn’t seem to.

    Clicking mark as read doesn’t seem to do anything, but if I then view some of the coments returning to the home page says “There are no unread comments”. However closing Firefox and then restarting and returning to the site lists all unread comments again.

    Opera seems to very nearly work – just the mark all as read option not working.

    Any suggestions? Is oit Firefox settings or a bug?

  27. Just a quick note and a thanks for the plugin. Got it integrated into my new theme design and it looks just grand.

    -tg

  28. No matter how many unread comments there are, it always returns there is 1 more unread comment. Is the number too large for the first visit?

  29. […] neric Recent Comments tracker in the sidebar, a new Unread Comments tracker (thanks to the Smart Unread Comments plug-in) shows only the comments you haven […]

  30. […] have also introduced an unread comment section using the Smart Unread Comments plugin from inner.geek I ran across today in The Robservatory. It’s p […]

  31. […] , голямо нещо Друг плъгин, който много ме радва, е […]

  32. […] , голямо нещо Друг плъгин, който много ме радва, е […]

  33. […] anzeigt – wie zB in Foren als eingeloggter User – hatte ich bisher nicht gefunde. Bisher. Smart Unread Comments macht exakt das: Creates a list of posts w […]

  34. Hi, have you ever thought of making a “recent posts” plugin? Should be quite easy I guess, just tweaking a little. There are a lot of recent posts plugins, yet I’ve found none with that “smart” useing cookies. I’m not into php-programming, I’d take ages for me to alter your plugin for posts… (so in case you do, let me know ;-))

  35. […] Show what’s new – forums have done this well in the past by indicating the number of new comments since your last visit. Drupal offers this for all commented on content. There’s a WordPress plugin for unread comments. Of course, comment RSS feeds or email notifications can be used to track new comments on posts that interest you too. […]

  36. Hey, just found your plugin through Google. Wow, looks pretty nice! I’m running WP 2.0 RC3 with some plugins involved, I’ll give it a spin tomorrow. I just wanted to comment on mzeecedric’s suggestion for a similarly “intelligent” recent posts plugin. I agree very much. Features that are enhancing a visitor’s surfing experience are very welcome.
    [ Okay, now I’m thinking of something like “Hello XX – 10 Posts, that you haven’t read here but might interest you, sorted by popularity:”, but that’s another story. 😉 ]
    Keep up the good work! I’m just writing a little article on the IMHO best “customizable post listing” plugins, including e.g. “Popularity Contest”. I’ll look into yours as soon as I can.

  37. […] I’ve installed the Smart Unread Comments plugin at the top of the posts area, which should allow my visitors to see any new comment posts since their last visit, provided they’re using cookies. […]

  38. My name is Ruby i am working on a big project at high school about blogs. I hope you don’t mind me mailing a few words on this text as my tutor needs to see it. Your blog is really good by the way.

  39. The download for this plugin doesn’t seem te work.

    Niels

  40. nice plugin for my blog, thanks for work, more plugins for wordpress here : Word press

  41. thank you for your blog, it’s interesting

  42. The necessary plugin (:
    It is established easily and perfectly works.
    Thank u so much!

  43. kishmish

    hi there
    is there any way of using this plugin in Admin section in combination with “Paged Comment Editing” where one can have overview of all comments at once.

    I was thinking to list all the comments and give a differenct background to unread comments.

    is this possible?

  44. […] Por cierto, como novedad he instalado un plugin con el que seguir los comentarios que se van registrando. Conseguir que la conversación no se pierda (”como lágrimas en la lluvia”) es una de las cosas a las que más tiempo llevo dando vueltas y creo que esto es un acercamiento bastante interesante. […]

  45. […] Smart Unread Comments: Permite, mediante el uso de cookies, mostrar al usuario una lista de los comentarios escritos desde su última visita. […]

  46. […] like to thank Brett Taylor, as I based this plugin on his Smart Unread Comments plugin, and Show Unread Comments wouldn’t be nearly as good without using his plugin as a […]

  47. […] Smart Unread Comments: Permite, mediante el uso de cookies, mostrar al usuario una lista de los comentarios escritos desde su última visita. […]

  48. […] cookie. Users can also mark all comments as read. Change Log: 2 entries Author: Brett Taylor Plugin Page Attached […]

Comments are closed.