1
#1
Private Messages Counting
Posted January 10th 2012, 6:36am
How many ways are availabe to count new private messages on a forumotion forum ?

I just want to have the number like "1" or "2" (withought the quote symbols)

Thank you in advance !
φ
Posts: 35
Joined: October 21st 2011, 11:00pm
Likes Given: 4
Likes Received: 2
Private Messages Counting
Posted January 10th 2012, 8:05am
Is your question how to do it or how many ways there are?
Because there are infinite ways lol... it depends how you write the script.

There are a few threads about that here.
http://www.diondesigns.org/t8588-
http://www.diondesigns.org/t8585-
φ
Posts: 509
Joined: July 9th 2011, 11:00pm
Location: England
Likes Given: 15
Likes Received: 26
Private Messages Counting
Posted January 10th 2012, 10:43am
There is a code for that one, it's somewhere in this forum...
φ
Posts: 209
Joined: September 10th 2011, 11:00pm
Location: SC, USA
Likes Given: 8
Likes Received: 8
Private Messages Counting
Posted January 10th 2012, 11:08am
As long as you have the default navbar on your page, this will retrieve the current PM count...if that was what you meant?

$(function() {
var pm = document.getElementById('i_icon_mini_new_message');
pm = pm && pm.title.split(' ')[2] || 0;

// Do something with the count...
});
φ
Posts: 64
Joined: June 17th 2011, 11:00pm
Location: 127.0.0.1/
Likes Given: 3
Likes Received: 2
Private Messages Counting
Posted January 10th 2012, 2:03pm
LGforum said:
Is your question how to do it or how many ways there are?
Because there are infinite ways lol... it depends how you write the script.

There are a few threads about that here.
http://www.diondesigns.org/t8588-
http://www.diondesigns.org/t8585-


Well I want a way that will not hit the request limit of the server getting this stupid message "Request Limit Exceeded"... My currrent way is ajax which gets requests to the server go up :(

Saxaca said:
As long as you have the default navbar on your page, this will retrieve the current PM count...if that was what you meant?

$(function() {
var pm = document.getElementById('i_icon_mini_new_message');
pm = pm && pm.title.split(' ')[2] || 0;

// Do something with the count...
});


I do not have the default navbar... I created one myself
φ
Posts: 35
Joined: October 21st 2011, 11:00pm
Likes Given: 4
Likes Received: 2
1
#6
Private Messages Counting
Posted January 10th 2012, 3:19pm
remove the script that uses Ajax for such a task then. Its silly.

Add this to your overall header below the BODY tag:
<div style="display:none">{GENERATED_NAV_BAR}</div>


And use the code Saxaca provided.
φ
Posts: 509
Joined: July 9th 2011, 11:00pm
Location: England
Likes Given: 15
Likes Received: 26
Private Messages Counting
Posted January 10th 2012, 11:33pm
Would that make the loading of my forum slower ?
φ
Posts: 35
Joined: October 21st 2011, 11:00pm
Likes Given: 4
Likes Received: 2
Private Messages Counting
Posted January 11th 2012, 8:12am
Using the Ajax one will make the loading slower.
Using the method provided by Saxaca and me will make your forum slower by about 0.0001s ... so no, lol.
φ
Posts: 509
Joined: July 9th 2011, 11:00pm
Location: England
Likes Given: 15
Likes Received: 26
Private Messages Counting
Posted January 11th 2012, 9:54am
well... have you written a tutorial about this? :D
φ
Posts:
Avatar
Guest
Private Messages Counting
Posted January 11th 2012, 1:05pm
LGforum said:
Using the method provided by Saxaca and me...

And the circle is complete. :P

http://www.webartzforum.com/t2442-#35996
φ
Posts: 1599
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
Private Messages Counting
Posted January 11th 2012, 5:35pm
I have question

var x = document.getElementById('i_icon_mini_new_message');
if (x) {
$('ul.topnav a[href="/privmsg?folder=inbox"]').after('<span class="dionPM">' + x.title.split(' ')[2] + '</span>');
}


what is the utility of this part

if (x) {
φ
Posts: 163
Joined: August 5th 2011, 11:00pm
Location: Pakistan
Likes Given: 34
Likes Received: 3
Private Messages Counting
Posted January 11th 2012, 11:26pm
Dion said:
LGforum said:
Using the method provided by Saxaca and me...

And the circle is complete. :P

http://www.webartzforum.com/t2442-#35996


To use this code should I keep the default loaded on page ? I've added it into my furum like that:

<script type="text/javascript">
var x = document.getElementById('i_icon_mini_new_message');
if (x) {
$('ul.topnav a[href="/privmsg?folder=inbox"]').after('<span class="dionPM">' + x.title.split(' ')[2] + '</span>');
}
</script>


But it does not work :cry: Should this give me the number only ?

Can you help me more ? I am sorry but I am new to javascript and all stuff like that Image

Thank you..!
φ
Posts: 35
Joined: October 21st 2011, 11:00pm
Likes Given: 4
Likes Received: 2
Private Messages Counting
Posted January 12th 2012, 8:04am
It will inly give you the number if there is a new message.

Change it to this for a '0'
var x = document.getElementById('i_icon_mini_new_message');
if (x) { pm=x.title.split(' ')[2]; } else { pm='0'; }
$('ul.topnav a[href="/privmsg?folder=inbox"]').after('<span class="dionPM">' + pm + '</span>');
φ
Posts: 509
Joined: July 9th 2011, 11:00pm
Location: England
Likes Given: 15
Likes Received: 26
Private Messages Counting
Posted January 12th 2012, 10:06am
Should I keep the default navbar loaded but hidden or not ?
φ
Posts: 35
Joined: October 21st 2011, 11:00pm
Likes Given: 4
Likes Received: 2
Private Messages Counting
Posted January 12th 2012, 1:20pm
ioncube said:
what is the utility of this part

if (x) {

Technically, no value. :P That part of the code was added because the OP in that topic only wanted a number displayed when there were new PMs.
φ
Posts: 1599
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
Private Messages Counting
Posted January 13th 2012, 12:00pm
I've tried all the codes but none of them worked for me :( :( I kept the default navbar loaded and I changed the '$' into 'jQuery' but still nothing..! Please help me...
φ
Posts: 35
Joined: October 21st 2011, 11:00pm
Likes Given: 4
Likes Received: 2
Private Messages Counting
Posted January 13th 2012, 12:12pm
you'll need to change this bit accordingly.
$('ul.topnav a[href="/privmsg?folder=inbox"]')

Depending on where your wanting the number to go.
φ
Posts: 509
Joined: July 9th 2011, 11:00pm
Location: England
Likes Given: 15
Likes Received: 26
Private Messages Counting
Posted January 13th 2012, 12:27pm
Would something like that:

<script type="text/javascript">
var x = document.getElementById('i_icon_mini_new_message');
if (x) {
jQuery('div.testpm').after('<span class="dionPM">' + x.title.split(' ')[2] + '</span>');
}
</script>


<div class="testpm"></div>


be correct ?
φ
Posts: 35
Joined: October 21st 2011, 11:00pm
Likes Given: 4
Likes Received: 2
Private Messages Counting
Posted January 13th 2012, 1:18pm
Put the DIV before the script, and things should work fine...
φ
Posts: 1599
Joined: March 12th 2009, 11:00pm
Location: Uncertain due to momentum
Likes Given: 26
Likes Received: 357
Private Messages Counting
Posted January 14th 2012, 4:33am
Dion said:
Put the DIV before the script, and things should work fine...


Thank's !

I followed your instructions and now I get another problem:

The message on the navbar is: "You have 1 new message"

and the code gives me:

the word "new" not the number... :(

I am using this code:

<div class="testpm"></div>


<script type="text/javascript">
var x = document.getElementById('i_icon_mini_new_message');
if (x) {
jQuery('div.testpm').after('<span class="dionPM">' + x.title.split(' ')[2] + '</span>');
}
</script>


How can I get the "1" only :)
φ
Posts: 35
Joined: October 21st 2011, 11:00pm
Likes Given: 4
Likes Received: 2

Who is online

Users browsing this forum: No registered users and 0 guests