Register Members List Search Today's Posts Mark Forums Read

Reply
 
Article Options
vBulletin Template Conditionals
HMBeaty
Join Date: Sep 2005
Posts: 4,141

I have no details

Morristown, TN
by HMBeaty HMBeaty is offline 01 Jun 2009
Rating: (4 votes - 4.75 average)

Just a little something I got permission from Brandon here to post here on vB.org. I figured that it would come in handy to quite a few people especially those of us who code so much. I've had to refer back to this several times myself.

I'll be adding more periodically but if you have any of your own, please feel free to add them to this thread. Thank you!

Display Information To Members Only
--------------------------
If you want to show a link only to registered members you would use this conditional.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Display Information To Guests Only
--------------------------
The following conditional will display information only to guests and no one else. This is helpful in displaying a welcome message that you only wish for guests to see.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

If Viewer is in the Following Usergroups Array. Enter the Usergroup Number(s) Seperated by a Comma
--------------------------
If you want to show an advertisement to viewers that are unregistered, registered members and awaiting email confirmation you would use the usergroup ids 1,2,3 within the array.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

If This Script Is or Is Not XXX
--------------------------
If this script is index (as used in the example below) then it will show the code within the conditional. You can use it to show a piece of code only on Forumhome if you have to put it in a template that is global such as the header. To find out what the script is per page open up the php file that loads the page like for instance showthread.php and look for.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

And the showthread part is what you would use.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

And here you can show information on every page but the index page by using this conditional.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

If this user equals or does not equal XXX
--------------------------
What this conditional will do is only show certain information if the person viewing the page has the same userid as defined within the conditional. So if you put userid 667 inside the conditional below and put a link inside the conditional tags only the user that has the userid 667 will see that link.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

And it works the opposite way as well if you do not want information to show for 667 but you want it to show for everyone else you would use.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Display Information On a Per Forum Basis
--------------------------
This conditional allows you to display information on a per forum basis. This can be helpful if you wish to display different advertisements depending on what forum that the user is in. You would simply replace X with the forum id that you wish the information to appear in.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

And on the other hand you can use the ! to do the opposite and display the information in every forum but the id you list.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Or if you have multiple forums you wish to include something with you can use an array such as this.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

If Usergroup Is or Is Not X
--------------------------
If the user is a member of the x usergroup then show the code.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

And then you can use the ! to tell it to not show it to the x usergroup but show it to everyone else.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

If Users Birthday is Less Than or Greater Than XXXX-XX-XX Do Something
--------------------------
Just to show the power of vBulletin here is a cool conditional that will show information based on the birthday of the user. The one below will show "Too Young" if they were born after 01-01-1980.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

And this one will show you "Too Young" if the user was born before 01-01-1980.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

If Thread is or is not in X Forum Execute Code
--------------------------
For instance if you want a piece of code to appear within thread in a particular forum you can do so with this conditional.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

If you want to show the piece of code on every new reply on every thread but 1 forum you can use this which says if thread is in forum x do not show the code but show it for all the other threads out side of forum x.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

And of course you can define multiple forum ids with the array.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Is user moderator of any forum?
--------------------------
If the user is a moderator execute code.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Is user moderator of current forum?
--------------------------
If the user is a moderator of the current forum execute code.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Is user moderator of X Forum?
--------------------------
If the user is a moderator of x forum execute code.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Is user the thread starter?
--------------------------
Is the user the thread creator? If so execute code.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Thread is closed?
--------------------------
If the thread is closed execute code.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Place Information After First Post
--------------------------
Useful for adding a advertisement or other information after the first post on every page.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Place Information After x Post On Every Page
--------------------------
This will add your code directly after the post number you define on each page. If you put 2 in place of x the code will appear on every page after the second post.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Using If Else in Templates
--------------------------
You can also use If Else conditionals within your templates. The below shows you how to correctly do this.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Views: 33913
Reply With Quote
Comments
  #2  
Old 01 Jun 2009, 02:02
Brandon Sheley's Avatar
Brandon Sheley Brandon Sheley is offline
 
Join Date: Mar 2005
Real name: Brandon
hope it's helpful for everyone
__________________
-----==== Check out The Best Forum Ever! & my new biz Sheley Enterprises =====-----
I offer contract work marketing and modifying forums, let me know if you have any questions.
Reply With Quote
  #3  
Old 03 Jun 2009, 12:25
Audax666's Avatar
Audax666 Audax666 is offline
 
Join Date: Jun 2008
Location: Germany
Oh yes it is! Thanks a lot.
If I knew yesterday that you publish that list today I would have saved a lot of time.
But for the next time it's a great effort.
__________________
That's all folks....

Thanks for visiting my projects:
laser tv news - rockabilly forum
Reply With Quote
  #4  
Old 25 Jun 2009, 10:46
EidolonAH EidolonAH is offline
 
Join Date: May 2009
Real name: Eidolon
Originally Posted by Redlinemotorsports View Post
Display Information To Guests Only
--------------------------
The following conditional will display information only to guests and no one else. This is helpful in displaying a welcome message that you only wish for guests to see.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

If Viewer is in the Following Usergroups Array. Enter the Usergroup Number(s) Seperated by a Comma
You wouldn't believe it, I have spent over 4 hours searching the net for ways to hide javascript from logged in users, all the time the answer was right here, and a simple solution too.
Many thanks for this, it has helped immensely.
Reply With Quote
  #5  
Old 04 Jul 2009, 11:28
steveneff steveneff is offline
 
Join Date: Sep 2007
Hello

Is there a condition for members first post within a thread, I would like to set sigs so they only show up once for each member in a thread
Reply With Quote
  #6  
Old 04 Jul 2009, 11:31
HMBeaty's Avatar
HMBeaty HMBeaty is offline
 
Join Date: Sep 2005
Real name: Brooks
Originally Posted by steveneff View Post
Hello

Is there a condition for members first post within a thread, I would like to set sigs so they only show up once for each member in a thread
You can do the same thing with this. I'm using 3.8.3 and works fine
__________________
"Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time!"
"It's important to only think about what you desire, not what you fear to achieve your ultimate goal!!
Reply With Quote
  #7  
Old 04 Jul 2009, 11:45
steveneff steveneff is offline
 
Join Date: Sep 2007
perfect, thanks
Reply With Quote
  #8  
Old 04 Jul 2009, 11:46
HMBeaty's Avatar
HMBeaty HMBeaty is offline
 
Join Date: Sep 2005
Real name: Brooks
No problem
__________________
"Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time!"
"It's important to only think about what you desire, not what you fear to achieve your ultimate goal!!
Reply With Quote
  #9  
Old 01 Sep 2009, 20:31
DinarMet DinarMet is offline
 
Join Date: Feb 2006
With template conditionals, is there a way to create an IF statement based on the URL?

For example, I have

http://..../forums/portal.php?pageid=books

http:/..../forums/portal.php?pageid=art

I would like to put a different images and links in the header for each page and thought that an IF statement would work based on the URL.

Is there a way to do this in the vBulletin header?

Thanks for you help

DM

--------------- Added 01 Sep 2009 at 17:38 ---------------

I was able to figure it out.

I am using vBadvanced and found that all I have to do is substitute $forum and forumid with $pages and pageid

So instead of this:
<if condition="$forum[forumid] == X"></if>

I used:
<if condition="$pages[pageid] == X"></if>

The page id's are available in the Admin Panel ->> vBa CMPS similarly the way forum id's are in the Forum Manager.

I posted it here in case anyone need to know. If you need to move it elsewhere then please do so.

Have a great day!

DM

Last edited by DinarMet; 01 Sep 2009 at 22:01. Reason: Auto-Merged DoublePost
Reply With Quote
  #10  
Old 03 Sep 2009, 21:25
ilrglen's Avatar
ilrglen ilrglen is offline
 
Join Date: Jun 2008
Real name: Glen Kohut
This is very helpful. Thanks.

Can these conditionals be inserted directly into the header template to have a message appear to one usergroup in the header of every page they try to enter (eg. I want to tell them their temporary access has expired and they will have to purchase a membership to continue)?
Reply With Quote
  #11  
Old 03 Sep 2009, 21:49
HMBeaty's Avatar
HMBeaty HMBeaty is offline
 
Join Date: Sep 2005
Real name: Brooks
Yes they can
__________________
"Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time!"
"It's important to only think about what you desire, not what you fear to achieve your ultimate goal!!
Reply With Quote
  #12  
Old 03 Sep 2009, 22:26
ilrglen's Avatar
ilrglen ilrglen is offline
 
Join Date: Jun 2008
Real name: Glen Kohut
So something like this

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

would work in the header?
Reply With Quote
  #13  
Old 03 Sep 2009, 22:34
HMBeaty's Avatar
HMBeaty HMBeaty is offline
 
Join Date: Sep 2005
Real name: Brooks
Not in the header, for the header, you would use

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

__________________
"Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time!"
"It's important to only think about what you desire, not what you fear to achieve your ultimate goal!!
Reply With Quote
  #14  
Old 03 Sep 2009, 22:41
ilrglen's Avatar
ilrglen ilrglen is offline
 
Join Date: Jun 2008
Real name: Glen Kohut
Originally Posted by Redlinemotorsports View Post
Not in the header, for the header, you would use

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.
I tried this out using usergroup 6 hoping that nobody else would see if but myself. It worked when I did it the way that I suggested in the header but not the way you did. Then when I changed it to usergroup #20 I was still able to see it. Are administrators able to see everything other usergroups see also?
Reply With Quote
  #15  
Old 03 Sep 2009, 22:44
HMBeaty's Avatar
HMBeaty HMBeaty is offline
 
Join Date: Sep 2005
Real name: Brooks
the "!" means if they are not it "usergroup id 20" they will see that message
__________________
"Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time!"
"It's important to only think about what you desire, not what you fear to achieve your ultimate goal!!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Article Options

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


New To Site? Need Help?

All times are GMT. The time now is 16:40.

Layout Options | Width: Wide Color: