Hey there,

I was wondering if you could suggest some PHP to use to for a block to display the number of unread messages for a user from your PrivateMsg module.
My aim is to write a snippet of code that will display a link to your '/messages' page and then the number of unread messages for that user. So it looks like ...

  • Inbox (4)
  • ...where 4 is the number of unread messages. It would a great if you could maybe incorporate as a block in your module as standard.

    Thanks for your help!

    Russ

    Comments

    berdir’s picture

    This does already exist... look for a block called "Privatemsg links" or so, it contains 3 links, "write new message", "inbox (x new)" and "sent".

    Russellf’s picture

    Ahah, brilliant! Thanks!

    Russellf’s picture

    Status: Active » Closed (fixed)
    Anonymous’s picture

    For themers, it could be usefull. This works on d6 :

    <?php 
          $count = privatemsg_unread_count();
          if ($count) {
            print l( '(' . (int)privatemsg_unread_count() .' new)' , "messages",  array('title' => 'View Inbox')); 
          }
        ?>
    

    And this is for d5 :

    <?php 
          $count = _privatemsg_get_new_messages();
          if ($count) {
            print l( '(' . (int)_privatemsg_get_new_messages() .' new)' , "messages",  array('title' => 'View Inbox')); 
          }
        ?>
    
    BeaPower’s picture

    Version: » 7.x-1.2

    How about for d7 to use in views with php custom field?

    BeaPower’s picture

    Status: Closed (fixed) » Active
    berdir’s picture

    Status: Active » Fixed

    This works exactly the same way in D7 as it does in D6. You can optionally pass in the user object to the the unread messages count of another user.

    BeaPower’s picture

    I tried that in views, but I get no output, nothing.

    Status: Fixed » Closed (fixed)

    Automatically closed -- issue fixed for 2 weeks with no activity.