vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   vBulletin Template Conditionals (https://vborg.vbsupport.ru/showthread.php?t=215032)

HMBeaty 05-31-2009 10:00 PM

vBulletin Template Conditionals
 
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.
HTML Code:

<if condition="$show['member']"></if>
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.
HTML Code:

<if condition="$show['guest']"></if>
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.
HTML Code:

<if condition="is_member_of($vbulletin->userinfo, 1, 2, 3)"></if>
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.
HTML Code:

define('THIS_SCRIPT', 'showthread');
And the showthread part is what you would use.
HTML Code:

<if condition="THIS_SCRIPT == 'index'"></if>
And here you can show information on every page but the index page by using this conditional.
HTML Code:

<if condition="THIS_SCRIPT != 'index'"></if>
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.
HTML Code:

<if condition="$bbuserinfo['userid'] == 667"></if>
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.
HTML Code:

<if condition="$bbuserinfo['userid'] != 667"></if>
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.
HTML Code:

<if condition="$forum[forumid] == X"></if>
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.
HTML Code:

<if condition="$forum[forumid] != X"></if>
Or if you have multiple forums you wish to include something with you can use an array such as this.
HTML Code:

<if condition="in_array($forum['forumid'], array(1,2,3,6))"></if>
If Usergroup Is or Is Not X
--------------------------
If the user is a member of the x usergroup then show the code.
HTML Code:

<if condition="$post['usergroupid'] == 6"></if>
And then you can use the ! to tell it to not show it to the x usergroup but show it to everyone else.
HTML Code:

<if condition="$post['usergroupid'] != 6"></if>
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.
HTML Code:

<if condition="$bbuserinfo['birthday_search'] > '1980-01-01'">Too Young</if>
And this one will show you "Too Young" if the user was born before 01-01-1980.
HTML Code:

<if condition="$bbuserinfo['birthday_search'] < '1980-01-01'">Too Young</if>
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.
HTML Code:

<if condition="$thread['forumid'] == X"></if>
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.
HTML Code:

<if condition="$thread['forumid'] != X"></if>
And of course you can define multiple forum ids with the array.
HTML Code:

<if condition="in_array($thread['forumid'], array(1,2,3,6))"></if>
Is user moderator of any forum?
--------------------------
If the user is a moderator execute code.
HTML Code:

<if condition="can_moderate()"></if>
Is user moderator of current forum?
--------------------------
If the user is a moderator of the current forum execute code.
HTML Code:

<if condition="can_moderate($forum['forumid'])"></if>
Is user moderator of X Forum?
--------------------------
If the user is a moderator of x forum execute code.
HTML Code:

<if condition="can_moderate($forum['x'])"></if>
Is user the thread starter?
--------------------------
Is the user the thread creator? If so execute code.
HTML Code:

<if condition="$threadinfo['postuserid'] == $bbuserinfo['userid']"></if>
Thread is closed?
--------------------------
If the thread is closed execute code.
HTML Code:

<if condition="!$show['closethread']"></if>
Place Information After First Post
--------------------------
Useful for adding a advertisement or other information after the first post on every page.
HTML Code:

<if condition="!$GLOBALS['FIRSTPOSTID']"></if>
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.
HTML Code:

<if condition="$post['postcount'] % $vboptions['maxposts'] == x"></if>
Using If Else in Templates
--------------------------
You can also use If Else conditionals within your templates. The below shows you how to correctly do this.
HTML Code:

<if condition="$show['guest']">
 Show Guest This Message
<else />
 Show Everyone but guests this message
</if>


Brandon Sheley 06-01-2009 01:02 AM

hope it's helpful for everyone :)

Audax666 06-03-2009 11:25 AM

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.:up:

EidolonAH 06-25-2009 09:46 AM

Quote:

Originally Posted by Redlinemotorsports (Post 1821004)
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.
HTML Code:

<if condition="$show['guest']"></if>
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.

steveneff 07-04-2009 10:28 AM

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

HMBeaty 07-04-2009 10:31 AM

Quote:

Originally Posted by steveneff (Post 1842589)
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

steveneff 07-04-2009 10:45 AM

perfect, thanks

HMBeaty 07-04-2009 10:46 AM

No problem :)

DinarMet 09-01-2009 07:31 PM

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! :up:

DM

ilrglen 09-03-2009 08:25 PM

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)?


All times are GMT. The time now is 08:23 AM.

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

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01352 seconds
  • Memory Usage 1,788KB
  • 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
  • (27)bbcode_html_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete