开发者

Buddypress Unread message count - live update?

I am using the following code to display the logged in users unread message count in a template.

  <?php if (messages_get_unread_count() != 0) { ?>

 <div id="message_count">
         <div class="countspan">
    <?p开发者_如何转开发hp echo messages_get_unread_count(); ?>
         </div>
     </div>
   <?php } ?>

This works great however it requires a page refresh to update. Since I am making heavy use of ajax driven navigation throughout the site and the custom apps within it this is not a satisfactory solution.

How can make the counter update automatically?

I have played around with the 'lvive notifications' plugin which polls the srver every 10 seconds to provide live notifications but of course this does not interact with my custom unread message counter.

Any ideas guys? I could really use the help.


I've worked it out...

It turns out buddypress has built in ajax functions for a lot of this stuff...

So for anyone else wanting to do the same thing.... It is a simple case of putting the 'count' inside an a link with the following id.

  <a id="user-messages">

<span><?php echo messages_get_unread_count(); ?></span>
</a>

Buddypress' javascript then does the rest for you. Simple!

Mana thanks for your suggestion though.


You could use setTimeout to periodically fire a request to the server which invokes your messages_get_unread_count() and returns a value.

Then based on the value returned, you could show or hide your <div id="message_count"> with the updated count.


You can do it with jQuery that calls a seperate php file like so.

jQuery.post('call.php',{ action: "get"}, function (data) {

        jQuery('#content').append(data);

    });

This tutorial walks you through it http://vavumi.com/?p=257

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜