The privatemsg module puts a link on the navigation menu that includes the number of unread private messages for the current user. That has been working fine, but I have created a new menu for my site, disabling the default navigation menu. I now need a way to alert users when they have new private messages. I am not sure where to start on this one. Has anyone here created a menu/snippet/block, etc. to do such a thing?

I could not find a formal spot for such comments on drupal.org, so I'm putting the following bit of praise along with my question: I have been using Drupal for a few months now, and I love it. I am in the middle of migrating a few thousand Mambo/Simpleboard posts to my new site, and beyond the trials and tribulations of that project, this has been a lot of fun. I just want to publicly thank all of you, who work on this project.

Nathan

Comments

michelle’s picture

I added this to my page.tpl.php:

    global $user;
    if ($user->uid) {
      print 'Welcome, <a title="Go to your account" href="/user/' . $user->uid . '">' . $user->name . '</a>';
      $numnew = _privatemsg_get_new_messages($user->uid);
      if ($numnew > 0) {
        print ' <a title="You have ' . $numnew . ' new message(s)"
                   href="/privatemsg">
                   <img src="/'.$directory.'/newmail.gif"
                        alt= "new mail" width="20" height="20" /></a>';
      }
    } else {
      print 'Welcome, Guest.
      Please <a href="/user/login">Login</a> or
      <a href="/user/register">Create an account</a>';
    }
    

It prints a line that says Welcome, Username and if they have any new messages it puts a little gif of a mailbox next to their name.

Michelle

NatCromlech’s picture

Thanks for the help. I am currently working on a phptemplate based layout for my site. I will integrate that code into it once I'm finished. My site is now using the Friends Electric theme, which I didn't want to modify, so I created a block based on your code. The block will only appear when a user has new private messages. Here's the code I'm using:

global $user;
$numnew = _privatemsg_get_new_messages($user->uid);
if ($numnew > 0) {
return ' <a title="You have ' . $numnew . ' new message(s)" href="/privatemsg">You\'ve got mail!</a>';
}
zc’s picture

nice work :)

Aerodynamo’s picture

I realize this is old, but I am looking for a way to do just this.

Is this still possible? It gives me errors when I try.