Drupal: How to add "Mark as Read" functionality to Organic Group's "My Unread" page.

We recently built a Social Networking Website for a client using Drupal combined with the Organic Groups Module. The client is very happy with the Website but requested the ability to mark Posts, Forum Topics and Comments as read from the "My Unread" page. This function was not built in by default. We were able to accomplish this functionality by creating a custom module that took advantage of the Views Bulk Operations module. The goal of this post is to walk you through the process step-by-step. The original inspiration for this article came from Self-made action "Set to read" works only with Bulk API.


  • Drupal
  • Organic Groups module
  • Views module
  • Views Bulk Operations module

This article will assume that you have installed and configured the requirements listed above.

The first thing you will need to do is create the custom module "Mark As Read". Here are the steps you will need perform.

  1. Create a folder inside of your Drupal "/sites/all/modules" directory named "mark_as_read".
  2. Open the mark_as_read directory and create the following files. - mark_as_read.info, mark_as_read.module
  3. Open the mark_as_read.info file with a text editor and paste the following text.
    		; $Id$
    name = Mark As Read 
    description = Mark As Read
    dependencies[] = 'views_bulk_operations'
    core = 6.x 
  4. Save the mark_as_read.info file.
  5. Open the mark_as_read.module and paste the following text.
    * Implementation of hook_action_info().
    function mark_as_read_action_info() {
        return array('mark_as_read_noderead_action' => array(
            'description' => t('Mark as read'),
    	'type' => 'node',
    	'configurable' => FALSE,
    	'hooks' => array(
    	    'nodeapi' => array('presave'),
    	    'comment' => array('insert', 'update'),  )   
    * Implementation of the actual function mark_as_read_noderead_action()
    function mark_as_read_noderead_action(&$node) {
        global $user;
        if ($user->uid) {
    	$sql = 'delete from {history} ' .
    	       "where nid='" . $node->nid . "' ".   
    	       "and uid='" . $user->uid . "'";
    	$sql = 'insert into {history} (nid,uid,timestamp) ' .
    	       "values ('" . $node->nid . "', '" . $user->uid . "', unix_timestamp()) ";
  6. Save the mark_as_read.module file.
  7. Navigate to "admin/modules" and enable your new module.

Next we will configure the view to take advantage of your new module.

  1. Navigate to "admin/build/views/edit/og_unread" and click the Page tab.
  2. Click the Style:Table link under Basic settings.
  3. Select Bulk Operations from the style options list. Click the Override button then click Update.
  4. Next select the your new Mark As Read option from the Selected Operations List.
  5. Click Update and then Save.

Now you can navigate to your My Unread page and enjoy your work.



Web Hosting:

Web HostingAt Nikkio, we offer full service Web Hosting solutions to our clients. This means we can help you find a home for your new or existing website. A number of hosting options are available to provide the space you need... More

ECommerce Solutions

eCommerce Increases Cash FlowNikkio offers a full range of eCommerce solutions. These solutions are ideal for a broad range of merchants, from those running small entrepreneurial ventures to those managing mature businesses. We can create a custom shopping cart... More

Database Design

database01Whether you have an existing database and need a conversion or want a new one, our database development team has the knowledge and experience to create a database customized to your businesses needs...More

Search Engine Optimization

Creating a beautiful website won’t do your business any good if your potential costumers can’t find it. The internet gives you the potential to reach millions of customers who are actively searching for your products or services... More