Log in

View Full Version : Code conditional on member post count


Jon12345
04-12-2012, 08:30 PM
I want to run some code but only if a member has >X number of posts and is logged in. Is that possible?

Thanks,

Jon

kh99
04-12-2012, 08:38 PM
What do you mean by "run some code"? Do you want to check for that condition in a plugin? I think it would be:

if ($vbulletin->userinfo['userid'] != 0 AND $vbulletin->userinfo['posts'] > X)
{
// run code
}


I'm not sure if you even need to check both, it may be that posts is always 0 or undefined for guests.

Jon12345
04-12-2012, 08:53 PM
Essentially, I want it for the thread view so that members who have 1,000 posts or more see less adds. I will try that code thanks. I knew there must be some way to do it but had no idea how. :)

--------------- Added 1334268405 at 1334268405 ---------------

I've just had a brainwave. :)

Is it possible to have some multiconditional stuff, like a Select Case used in some programming languages?

i.e. if over 5,000 posts show no ads, if over 1,000 show 1 ad, if under 1,000 show 2 ads?

kh99
04-12-2012, 09:46 PM
Yes, in a plugin you could use switch: http://us2.php.net/manual/en/control-structures.switch.php.

Another way would be to use usergroups - you can add "promotions" that will change a user's group (or add a secondary group) based on post count, and you could then decide on ads based on group. Don't know if that would be easier or not, but it's there.

Jon12345
04-12-2012, 09:51 PM
How about something like this?

if ($vbulletin->userinfo['userid'] != 0 AND $vbulletin->userinfo['posts'] > 1000 and $vbulletin->userinfo['posts'] < 2000)
{
// run code A
}
if ($vbulletin->userinfo['userid'] != 0 AND $vbulletin->userinfo['posts'] >= 2000 and $vbulletin->userinfo['posts']<5000)
{
// run code B
}

Would that work? Are you allowed to use >= next to one another?

kh99
04-12-2012, 09:55 PM
That looks OK to me. I suppose you might want "else if" for all but the first, that way you could have an "else" at the end if you wanted (although I suppose a last > test would do the same thing).

Jon12345
04-12-2012, 10:05 PM
Great, I will try the above code then. Thanks for the guidance. :)

--------------- Added 1334314628 at 1334314628 ---------------

I have just realised that I think the above code is if I am doing a plugin. But i want to just edit the template. To translate this into something that would work in a template, would my code attempt below be a fair translation?

<if condition="$vbulletin->userinfo['posts'] > 1000 and $vbulletin->userinfo['posts'] < 2000">

// run code A

</if>

--------------- Added 1334329256 at 1334329256 ---------------

Its ok, worked it out now!