View Full Version : Does $Post[Posts] return a String or Numeric ?
mistyPotato
07-31-2007, 11:41 PM
Hello All!
I would appreciate anyone giving me a bit of advice on this.....
I cannot get the value of $Post[Posts] to act like a number so I'm beginning to wonder if maybe this variable needs to be converted to a number for certain operations to work on it?
Thanks for your time :up:
Kirk Y
07-31-2007, 11:46 PM
It returns an integer. Where are you trying to use it?
Keep too in mind, that $Post and $post are two totally different variables. If you're using $Post[Posts], you should be using $post[posts].
mistyPotato
08-01-2007, 12:00 AM
Hello Kirk and thanks for the reply :up:
Gee, you're the first to tell me that Post and post are different variables. Now I'll go back and see if maybe that's been the problem. I've been trying to use a post count conditional in the post bit legacy template to place a graphic on the left (in the Users information box) based on their post count but so far I haven't been able to get it to work.
Here's the suspect :) code....
<if condition="$post[posts] > 1000"><img src="images/misc/Contributor1.gif"></if>
I've tried changin this every way I could imagine but it still doesn't work. Should I be using the CAPITAL P?
Thanks a million!
MP
Kirk Y
08-01-2007, 12:08 AM
Nope, that's how it should be. Make sure you've got the image pointing to the correct path. You should also be using a self-closing tag: <img src="/image/gif.gif" />; but that wouldn't affect it displaying either way.
mistyPotato
08-01-2007, 12:36 AM
Wow.
This is my dilemma. Everyone's told me "Yep. it's correct"....but it doesn't work :erm:
If I change the condition to something other than > 1000, such as == 1000, then it works...
so I know the image location is correct.
Seems the conditional does not like the greater than symbol :confused:
Kirk Y
08-01-2007, 12:44 AM
Are you certain that the user's have more than 1,000 posts?
mistyPotato
08-01-2007, 12:47 AM
We'll, their post count says over 3000 and when I look in the SQL tables I see members with over 1000 posts.
Isn't this odd ?
Kirk Y
08-01-2007, 01:05 AM
Hmm... quite.
Okay, let's try going about this another way. Create a new plugin using hook location "postbit_display_start" with the following:
if ($this->post['posts'] > 1000){
$image = '<img src="images/misc/Contributor1.gif" />';
}
Place $image in your postbit where you'd like the image.
Adrian Schneider
08-01-2007, 01:17 AM
Once it hits 1000 it is "1,000" so the comma is messing up your comparison.
mistyPotato
08-01-2007, 01:20 AM
Thanks again for your help Kirk. It's VERY nice of you to give of your time like this.
It is definitely appreciated.:up:
I added the plug in in hook but I wasn't sure how to add the $Image in the Post Bit Template.
(Did I mention I'm using the Legacy Post Bit Template?)
Do I just put $Image in the template where I want the image to appear?
Sir Adrian, I was Wondering about that. But if that were the case, anything UNDER 1000 should work...but it doesn't seem to either.
What's the difference between posts and postcount?
MP
Kirk Y
08-01-2007, 01:27 AM
Once it hits 1000 it is "1,000" so the comma is messing up your comparison.
I didn't realize that they were treated differently.
Thanks again for your help Kirk. It's VERY nice of you to give of your time like this.
It is definitely appreciated.:up:
I added the plug in in hook but I wasn't sure how to add the $Image in the Post Bit Template.
(Did I mention I'm using the Legacy Post Bit Template?)
Do I just put $Image in the template where I want the image to appear?
Sir Adrian, I was Wondering about that. But if that were the case, anything UNDER 1000 should work...but it doesn't seem to either.
MP
Yes, place $image wherever you'd like it displayed -- and remember $image and $Image are two totally separate variables.
mistyPotato
08-01-2007, 01:38 AM
Kirk....Kirk....Kirk..............
I THINK YOU'VE DONE IT. :up:
I've looked over about 100 posts and so far, the image IS showing up exactly where it should!
After struggling with this all day, I can't tell you how much I appreciate your expertise and help with this. Thank you for taking the time to follow through on this.
I wonder why it wouldn't work the other way :confused:
I would NEVER have thought to use a plug in like that.
I owe ya!
Best Regards,
MP
Kirk Y
08-01-2007, 01:42 AM
I really don't know why it wouldn't work; unless it is as SirAdrian suggested, that 1000 and 1,000 are treated differently.
In any event, I'm glad it's working for you.
Adrian Schneider
08-01-2007, 01:54 AM
Your code works because the plugin is processed before it adds the commas in. But yeah, that's why (for future reference). I've seen this happen to 3-4 different people know so it's an easy one to spot!
mistyPotato
08-01-2007, 02:05 AM
Thanks to you both :up:
Marco van Herwaarden
08-01-2007, 07:26 AM
Like SirAdrian already mentioned, $post['posts'] is NOT numeric, but formatted so it is a string.
Doing a numeric comparison on a string will first cast the variable to numeric ('1,000' will result in the longest integer possible from the start of the variable, resulting in '1' - everything after the comma gets ignored).
If you want to run a conditional on this, you will need to create a plugin that stores the original numeric value in a seperate variable, before formatting occurs.
Kirk Y
08-01-2007, 05:45 PM
Interesting, I never realized this.
Dismounted
08-02-2007, 10:32 AM
Most numeric values displayed by vBulletin are formatted with vb_number_format().
Kirk Y
08-02-2007, 02:01 PM
I actually discovered that last night while I was looking at the Forumhome statistics.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.