Hi, I want to show a link to a users inbox in my theme. This is easy with a direct link to privatemsg, but I wanted to show whether the user has any messages next to the link, like this: Inbox (3)

How can I do this?

Thanks for any help.

Comments

yngens’s picture

second

litwol’s picture

look in the private msg code to see how it implements such feature, then you can copy/paste that code into your theme.

yngens’s picture

line 182 says:

    if ($new && strncmp($_GET['q'], 'privatemsg', 10) && $user->privatemsg_setmessage_notify && user_access('access private messages')) {
      $m = drupal_set_message();
      if (empty($m)) {
        drupal_set_message(strtr(format_plural($new, 'You have a new <a href="!url">private message</a>.', 'You have @count new <a href="!url">private messages</a>.'), array('!url' => url('privatemsg'))));
      }
    }

unfortunately, for non-coders it is difficult to figure out how and where to apply this to get number of new messages on a menu item. by the way, the module has a block, which display the requested feature. but i really want to have that link not in the block, but be able to move around menu system.

yngens’s picture

Category: support » feature

Please move link showing number of new messages from the modules block to central menu system.

Jboo’s picture

I'm not sure of this is good coding as I'm rubbish with php but I have this working by adding this to my template.php:

 /**
*   INBOX WITH COUNT
*/
function custom_privatemsg_inbox() {
  global $user;
  if ($user->uid && user_access('access private messages') && (isset($user->privatemsg_allow) ? $user->privatemsg_allow : 1)) {
    $new = _privatemsg_get_new_messages();
    $items = print(
      l(t('Inbox') . ($new ? " ($new)" : ''), 'privatemsg')
    );
  }
} 

Is there a better way to do this?

sdsheridan’s picture

How do you invoke this?

Jboo’s picture

Call it from somewhere in your template files, e.g page.tpl.php like this:

<?php print custom_privatemsg_inbox() ?>

alex_shapka’s picture

Title: Add Inbox Link and No. of Messages to Theme » Please move link showing number of new messages from the modules block to central menu system

Original request had already been realized in Drupal - there is a special block that shows Inbox link and No's of messages. So I hope maintainers will be able to move that link in a block to the central menu system, thus enabling Drupal site administrators move this link anywhere they want around the menu system. For instance, I would like to place a link to Inbox with number of new messages shown in primary links, but I don't know how.

raffi’s picture

Anyone has a solution to this?

berdir’s picture

I'm closing old issues since this version isn't supported anymore.

Privatemsg 6.x both displays then number of new messages in a block and in the default menu system.

berdir’s picture

Status: Active » Closed (won't fix)
alexmoreno’s picture

privatemsg_unread_count();

the function custom_privatemsg_inbox throws an error.