WordPress Plugin: Mark as Read

21

For the first time ever I created my own plugin. Starting out as a hacking attempt, it quickly changed into a prototype plugin.

What it basically does is list the articles that haven’t been read yet by a logged in user. Whenever a change to the post is made or a new comment is posted, the post moves to the top of the unread list.

markasread

Download
Get the plugin!

Functionality:

Mark as Read makes it easy for your users to keep track of changes on your blog. Whenever a post is published or updated the post will show up in this list. When a new comment is posted, the post will also go up in this list and will be marked as “unread”.

Features:

  • Keeps track of which articles a logged in user has read.
  • Posts bump on new comments
  • Posts bump on published / updates
  • Customizable output
  • Lists per category or all categories
  • Usable non-output functions

Installation:

  1. Download the plugin
  2. Upload contents of the zip-archive (the folder) to the plugin directory of your WordPress installation (default: wp-content/plugins/)
  3. Enable the plugin through the plugin admin panel
  4. Paste code inside template file
  5. Enjoy!

Usage:

To output the list all you need to do is to put the following code inside a template file of your theme:

<ul>
<?php the_unread_posts(); ?>
</ul>

This will output all the unread content of all categories.

The following parameters are accepted:

the_unread_posts($categoryID, $noPostsMessage, $updateText, $rowStyle);

$categoryID (Optional, default: “all”):
Supply this parameter if you want to show unread messages from one category only. Give the string “all” if you want to display all categories.

$noPostsMessage (Optional, default: “<li>No unread posts</li>”):
Sets the output of an empty list.

$updateText (Optional, default: array(“New comment(s) and changes”, “Changes”, “New comment(s)”)):
Sets the output of the different types. Give an array with 3 values; first one being the output when a post has new comments and is updated, second for updates only and third for new comments only.

$rowStyle (Optional, default: “<li><a href=’%link%’>%type% on: %title%</a></li>”):
The HTML in which each post has to be shown. Use %link% to insert a permalink to the post, %title% for the post title and %type% for the type of change.

Articles like this one

If you liked this article you can add this post to:


 

20 Comments

  1. Kawsar Ali said: June 9, 2009 at 6:36 pm | Permalink

    Wow.. gaya keep the good stuff coming. I will give this a try.


  2. Gaya said: June 9, 2009 at 8:02 pm | Permalink

    Thanks Kawsar! Hope you can put it to great use.


  3. Miriam said: June 11, 2009 at 4:01 pm | Permalink

    Does this work for changes made on Pages too?


  4. baron said: June 11, 2009 at 4:06 pm | Permalink

    Works great, thank you


  5. Gaya said: June 11, 2009 at 4:37 pm | Permalink

    @Miriam: good thinking! that might be something for the future ;)

    @baron: Thanks!


  6. Alloy said: June 17, 2009 at 2:20 am | Permalink

    Hi,, My bro… I Like your blog. Great design..!! :-)


  7. hopefullytammy said: August 13, 2009 at 3:16 pm | Permalink

    Hi Gaya,

    I think your plugin might be incompatible with the current version of WordPress? Or am I doing something wrong? I did a fresh install of WP 2.8.2 (latest as of today) but I keep getting these errors:

    Warning: Missing argument 2 for comment_not_read() in /home/mysite/public_html/wp/wp-content/plugins/mark-as-read/storage.php on line 31

    Warning: Cannot modify header information – headers already sent by (output started at /home/mysite/public_html/wp/wp-content/plugins/mark-as-read/storage.php:31) in /home/mysite/public_html/wp/wp-includes/pluggable.php on line 865

    I get this error regardless of whether or not is pasted into the theme.

    Looking at the code in storage.php, the offending variable seems to be $approved:

    //insert the post that has not been read with COMMENT type, will be fired after a comment post
    function comment_not_read($comment_id, $approved) {
    $comment = get_comment($comment_id);

    insert_not_read($comment->comment_post_ID, “comment”);
    }

    Let me know if you have any ideas on this. Thank you!


  8. hopefullytammy said: August 13, 2009 at 8:30 pm | Permalink

    OK, in mark-as-read.php, I changed this line:
    add_action(“comment_post”, “comment_not_read”);

    to this:
    add_action(“comment_post”, “comment_not_read”, 10, 2);

    And that gets rid of the error message. (this fix was based on http://wordpress.org/support/topic/298291)

    However, I noticed that unapproved comments still show up as “unread” even though they are not live on the site.

    Maybe my change caused that? Or (more likely) it was like that before?


  9. Paul said: October 17, 2009 at 3:13 pm | Permalink

    Very useful, thanks


  10. Костоправ said: January 26, 2010 at 4:04 pm | Permalink

    Ну ничего себе, каждый ваш пост просто шедевр мировой литературы=)


  11. Ren said: August 13, 2010 at 4:23 am | Permalink

    Hi, this works well.

    I just have a question.

    How can I make it work for guests as well as right now, it only appears when users are logged in.

    Thanks.


  12. Pikkio said: August 27, 2010 at 2:13 pm | Permalink

    awesome plugin!! thanx!

    i have only 2 question2:
    1) can i set it up to get only the new comments displayed and not the post’s changes?

    2) it’s possible to set a maximum number of news displayed?


  13. Marcus said: September 4, 2010 at 11:40 am | Permalink

    Hi!
    I love the plugin. Can you tell me if it’s possible to set it to display 2 particular categories instead of just one or all?


  14. dai dai hua said: December 20, 2010 at 9:22 pm | Permalink

    Site visitors Mayhem Review- the content on this write-up is definitely a single of probably the most effective substance that i?ve in fact are obtainable throughout. I genuinely like your post, I’ll are accessible once more to verify for new posts.


  15. Mark said: February 17, 2011 at 10:20 pm | Permalink

    Any chance you could get this to work with rolescoper? It should be relatively easy… Rolescoper just allows an administrator to set user access certain posts. It turns out, that all members have the unread notifier, but cannot click the link to clear since they cannot link the page. I’d like the user to only have unread comments/posts if they have access to the posts in a particular category. Here’s the line to get the list of categories a user is allowed to access (taken from RoleScoper website):

    $cat_ids = get_terms( ‘category’, array( ‘fields’ => ‘ids’ ) );


  16. Jonathan said: April 7, 2011 at 3:20 am | Permalink

    Just a suggestion, it would be really great to be able to define a category to EXCLUDE from displaying. Or even multiple. I have certain posts that only exist to go into a content slider, or that exist to be pulled into other things and are not meant to actually be seen as posts. I can give these all a category of “hidden” and as long as I can select to exclude that category from the unread plugin, then I’m home free and they won’t show up in the list.

    Jonathan


  17. Jonathan said: May 24, 2011 at 2:03 am | Permalink

    Can’t figure out why this plugin is returning only 5 results no matter what. I don’t see any limit in the code anywhere, yet that’s all I ever get – the last 5 unread updates.

    Is there still any active support for this?


  18. Suraj said: July 28, 2011 at 10:21 pm | Permalink

    Hey Jonathan, I just encountered the same problem. It’s because the wordpress function get_posts() automatically pulls the first 5 posts. Change this in the functions.php: add ‘numberposts’ => 100, or whatever you need.


  19. shino said: December 18, 2011 at 3:41 am | Permalink

    Thanks! It’s what I wanted!!!


  20. Jeff said: January 25, 2012 at 4:14 pm | Permalink

    I installed 0.9 of the plugin and the menu option under Settings is not showing up. Has anyone experienced this and found a solution?

    I do have the plugin working fine on another site (i.e. menu option shows).

    Thanks!


Leave a Comment

Your email is never shared. Get your own avatar with gravatar! Required fields are marked *

*

*