vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Code conditional on member post count (https://vborg.vbsupport.ru/showthread.php?t=281484)

Jon12345 04-12-2012 08:30 PM

Code conditional on member post count
 
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:

Code:

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 [DATE]1334268405[/DATE] at [TIME]1334268405[/TIME] ---------------

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...res.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?

Code:

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 [DATE]1334314628[/DATE] at [TIME]1334314628[/TIME] ---------------

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?

Code:

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

  // run code A

</if>

--------------- Added [DATE]1334329256[/DATE] at [TIME]1334329256[/TIME] ---------------

Its ok, worked it out now!


All times are GMT. The time now is 11:16 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01017 seconds
  • Memory Usage 1,725KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete