Skip to content
WJunction - Webmaster Forum

Using Vbulletin Conditionals

Status
Not open for further replies.
Hi Guys,
Thought i'd write a tutorial on using vBulletin conditionals, i got some spare time :)

What is a conditional?
Basically, its an <if> tag that checks if something is true or not.
Whatever the conditional is wrapper around is only executed/seen if the condition is met, hence the name conditional

Some Common Conditionals:
First of all Note that these conditionals havent been found by me, etc. I just googled for em :P
Anyway hers a few that i find useful

Code:
<if condition="is_member_of($vbulletin->userinfo, X, Y, Z)"></if>
Anything wrapped in this conditional would only display to members of usergroups X,Y or Z. OBviously u can add more to the array.

Code:
<if condition="THIS_SCRIPT == 'index'">
Lets say you've got your ad on your header but you only want to display it on your index page. This is what this conditional does. To find out the name of the page, you have to look at the php file itself and look for
Code:
define('THIS_SCRIPT', 'index');

Code:
<if condition="$bbuserinfo['userid'] == 667">
This would only show the content to one user, in this case user 667

Code:
<if condition="in_array($forumid, array(X,Y,Z))">
What this does, is display the content in only a certain forum, with X,Y,Z being replace with the forum id

Code:
<if condition="$bbuserinfo['birthday_search'] > '1980-01-01'">
What this does is check the birthday of the user. Obviously replace 1980-01-01 with the birthday you want. Very Useful in adult sections.

Code:
<if condition="can_moderate($forum['X'])">
This checks if the user is a moderator of the current forum. Replace X with the forumid

Code:
<if condition="$threadinfo['postuserid'] == $bbuserinfo['userid']">
This checks if the user is the thread starter or not. Still havent found ause for this one :P

Code:
<if condition="!$GLOBALS['FIRSTPOSTID']">
This is used to place something directly under the first post. Especially useful for ads, etc

Else and Not

Okay now for something a little more complex. With all these conditionals you can use an <else> tag to execute different information if the condition isn't met.

So for example:
Code:
<if condition="$bbuserinfo['birthday_search'] > '1980-01-01'">
<!---Adult section stuff here-->
<else>
Too Young
</if>

This would Display Too Younf if the user didnt meet the required age

There is also the ! character. If you put that infront of the =, the conditional will check if the condition is not met.
So for example
Code:
<if condition="$bbuserinfo['userid'] != 667">
Would display information to everyone BUT userid 667.

Some Common Screwups
I know i definately did this one a lot :P
Basically, Template Conditionals will only work in templates. Full Stop
I tried using em in bbcodes, was wondering why they didnt work :P
But yeah, now you know.



Finally got this finished, enjoy
-timtamboy63

Oh and let me know if u need any help
 

4 comments

Status
Not open for further replies.

About the author

T
Active Member · Joined
Picked up photoshop about half a year ago. Now i do graphics design :) Graphics/Web Design
885
Messages
0
Reactions
16
Points

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom