WordPress Plugin: Mark as Read
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.
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:
- Download the plugin
- Upload contents of the zip-archive (the folder) to the plugin directory of your WordPress installation (default: wp-content/plugins/)
- Enable the plugin through the plugin admin panel
- Paste code inside template file
- 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
10 Comments
-
Wow.. gaya keep the good stuff coming. I will give this a try.
-
Thanks Kawsar! Hope you can put it to great use.
-
Does this work for changes made on Pages too?
-
Works great, thank you
-
@Miriam: good thinking! that might be something for the future ;)
@baron: Thanks!
-
Hi,, My bro… I Like your blog. Great design..!! :-)
-
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!
-
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?
-
Very useful, thanks
-
Ну ничего себе, каждый ваш пост просто шедевр мировой литературы=)


Recent comments