[solved] Anyone know how? "IF postcount less than X"

Discussion forum for MOD Writers regarding MOD Development.
User avatar
Yukan
Registered User
Posts: 155
Joined: Mon Aug 27, 2007 5:06 pm
Location: http://localhost/

[solved] Anyone know how? "IF postcount less than X"

Post by Yukan »

In a style you can use IF statements to determine who sees what, well...

Code: Select all

<!-- IF "postcount higher then X" -->
I'd like a link to only appear to people with X posts or higher. Could anyone help me
with this? thank you in advance, I hope this is posted correctly. I know the above code
wont work, its just a plain English version of what i want it to do. :? Again thanks for any
help.
Last edited by Yukan on Mon Nov 23, 2009 10:09 am, edited 1 time in total.
User avatar
Sam
Former Team Member
Posts: 2082
Joined: Thu Jan 22, 2009 3:59 am
Location: Sacramento, CA
Name: Sam Thompson

Re: Anyone know how? "IF postcount less than X"

Post by Sam »

In your PHP:

Code: Select all

$template->assign_vars(array(
'X_POSTS' => ($user->data['user_posts'] > $min_posts) ? true : false;
));
Your Template:

Code: Select all

<!-- IF X_POSTS -->
code here if they have greater than $min_posts
<!-- ELSE -->
code here if they have less than or equal to $min_posts
<!-- ENDIF -->
You could also do a single alternative:

Code: Select all

<!-- IF X_POSTS -->
code here if they have greater than $min_posts
<!-- ENDIF -->
And you can negate it:

Code: Select all

<!-- IF not X_POSTS -->
code here if they dont have greater than $min_posts
<!-- ENDIF -->
Last edited by Sam on Mon Nov 23, 2009 1:46 am, edited 1 time in total.
User avatar
imkingdavid
Former Team Member
Posts: 2673
Joined: Sun Jul 26, 2009 7:59 pm
Location: EST
Name: David King

Re: Anyone know how? "IF postcount less than X"

Post by imkingdavid »

You could do something like the following... I'm not sure on the exact variables, but this is how you'd do it.

Open the page you want to restrict something in (the .php file).

Do something like the following (not sure exactly about the variable):

Code: Select all

if($user->data['user_posts'] >= 50)
{
   $template->assign_var('S_POST_CHECK', true);
}
Now in the template file (.html) do something like...

Code: Select all

<!-- IF S_POST_CHECK -->
Stuff to show to users with 50 or more posts
<!-- ENDIF -->
That should work in theory. Basically, just check your database user table to see what the row is called that has the number of posts made by the user. ;)

EDIT by way of post review: ahh, Syntax beat me to it. Well, it's the same idea, but use his code, since it'll probably work better. :D
Don't forget to smile today. :)
Please do NOT contact for support via PM or email.
User avatar
Yukan
Registered User
Posts: 155
Joined: Mon Aug 27, 2007 5:06 pm
Location: http://localhost/

Re: Anyone know how? "IF postcount less than X"

Post by Yukan »

@Syntax

Thanks, worked perfectly. :)

Return to “[3.0.x] MOD Writers Discussion”