Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
vBulletin Template Conditionals
HMBeaty's Avatar
HMBeaty
Join Date: Sep 2005
Posts: 4,141

I have no details

Show Printable Version Email this Page Subscription
HMBeaty HMBeaty is offline 05-31-2009, 10:00 PM

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>
Reply With Quote
  #52  
Old 02-03-2011, 03:07 PM
nikki712 nikki712 is offline
 
Join Date: Sep 2006
Posts: 105
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm sorry to be a pain, but this is what I used and the ads are still showing up on every forum. I have one particular forum where sponsors answer questions. This forum as an "Ask the Expert" forum with several child forums dedicated to each individual expert. I don't want ads for competitors showing up there. What is wrong with my code now? I have included the "Ask the Expert" forum ID, along with the IDs for all the child forums. Ads cannot show up in these forums, and I don't want the "experts" usergroup to see any at ads at all...on any forum.

Code:
<center><if condition="!in_array($forum['forumid'], array(32,48,34,44,41,49,53,58,61,79,82,81,80,46,52,36,40)) AND !is_member_of($vbulletin->userinfo, 7,14)"><script type="text/javascript"><!--
google_ad_client = "pub-xxxxxxxxxxxxx";
/* Forum Leaderboard */
google_ad_slot = "xxxxxxxxx";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></if></center>
Reply With Quote
  #53  
Old 02-03-2011, 03:18 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Where are you putting this code?

Some places user different variables, instead of $forum['forumid'] try $thread['forumid'] or $foruminfo['forumdid'] or $threadinfo['forumid'] (if you're in a thread).
Reply With Quote
  #54  
Old 02-03-2011, 03:28 PM
nikki712 nikki712 is offline
 
Join Date: Sep 2006
Posts: 105
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I've tested it on ad_navbar_below.

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

When I try the $foruminfo['forumdid'] code, the ad shows up as "page cannot be displayed". I'm gonna try the other two suggestions and see if they work.
Reply With Quote
  #55  
Old 02-03-2011, 04:42 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by nikki712 View Post
I've tested it on ad_navbar_below.

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

When I try the $foruminfo['forumdid'] code, the ad shows up as "page cannot be displayed". I'm gonna try the other two suggestions and see if they work.
It's $foruminfo then... if there's a problem the ad can't be shown that's an unrelated issue - a problem with your ad code.
Reply With Quote
  #56  
Old 02-03-2011, 04:53 PM
nikki712 nikki712 is offline
 
Join Date: Sep 2006
Posts: 105
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

None of these seem to work. I'm so frustrated b/c I've had a server load problem and have narrowed it down to the Adsense hack I have installed. I'm hoping to find a workaround for this by using these conditionals, but they don't want to cooperate with me.

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

The problem is that even though it said "page cannot be displayed", it was still showing up in a forum that it shouldn't be in. I made a test user and put it in the "experts" usergroup, and could see all ads.

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

I'm just going to try to get it to not show up in the experts forum, and forget about blocking ads throughout the entire forum for my experts group.
Reply With Quote
  #57  
Old 02-03-2011, 04:59 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I just tested this on my forum, it's definitely $foruminfo['forumid'] to show the ad code in specific forums (forumdisplay) and threads in that forum (showthread.)

If you get the page can't be displayed message in the ad box you have an error in the code you copied from google to show the ad. The fact that the box shows means the conditional is working.
Reply With Quote
  #58  
Old 02-03-2011, 07:06 PM
nikki712 nikki712 is offline
 
Join Date: Sep 2006
Posts: 105
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't know what I'm doing wrong, but if you don't mind, can you please take a look at my code and see if anything looks wrong? I'm copying the code directly from Google. My hack works fine, but I disable it to test out the conditionals.

Code:
<if condition="!in_array($foruminfo['forumid'], array(32,48,34,44,41,49,53,58,61,79,82,81,80,46,52,36,40))"><script type="text/javascript"><!--
google_ad_client = "pub-xxxxxxxxxxxxxxxxx";
/* Forum Leaderboard */
google_ad_slot = "xxxxxxxxxxx";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></if>
32,48,34,44,41,49,53,58,61,79,82,81,80,46,52,36,40 - Forum IDs I DON'T want ads shown in.

Also, could my PHP version be the problem? I'm running 5.2.16.

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

The answer is to use $GLOBALS instead of $foruminfo. Works like a charm!
Reply With Quote
  #59  
Old 02-03-2011, 08:13 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I copied your code into my forum and the condition works perfectly fine for me (in the ad_navbar_below template) which is shown in the navbar template...

What exactly isn't working? I can't test the google code obviously but it looks like it should work if you had numbers in place of the x's.

DO you have a kink to a forum this is running on?
Reply With Quote
  #60  
Old 02-03-2011, 10:29 PM
nikki712 nikki712 is offline
 
Join Date: Sep 2006
Posts: 105
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nope, no kinks. This code works:

Code:
<if condition="!in_array($GLOBALS['forumid'], array(32,48,34,44,41,49,53,58,61,79,82,81,80,46,52,36,40))"> AND <if condition="!is_member_of($vbulletin->userinfo, 1,2)">
Zachary at vb.com helped me out. He said to make them two separate conditionals like this:

Code:
<if condition="!is_member_of($bbuserinfo, 14)> 
<if condition="!in_array($GLOBALS[forumid], array(32,48,34,44,41,49,53,58,61,79,82,81,80,46,52,36,40))">
ADD CODE HERE
</if>
</if>
I haven't tried the last code, but will a little later on. I'll let you know how it goes. Thanks!!!

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

Oh, the problem was that the ads were showing up in the forums I didn't want them to show up in. They were also showing up to the usergroups I didn't want them showing up to. The "page cannot be displayed" was just a glitch with one of the image ads. That's all that was.
Reply With Quote
  #61  
Old 02-28-2011, 02:12 PM
PAKIDIL PAKIDIL is offline
 
Join Date: Jan 2007
Posts: 264
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i have problem in conditional coding too .

i am pasting this in one of my template ad location ad_showthread_firstpost

<if condition="THIS_SCRIPT != 'adv_index' AND THIS_SCRIPT != 'register' AND $GLOBALS[forumid] != 6">

and getting this error

Parse error: syntax error, unexpected ',' in /home/forum/public_html/includes/adminfunctions_template.php(3772) : eval()'d code on line 1

can anyone help ?.
Reply With Quote
Reply


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


All times are GMT. The time now is 01:56 PM.


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.06757 seconds
  • Memory Usage 2,349KB
  • Queries Executed 25 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (4)bbcode_code
  • (26)bbcode_html
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (11)post_thanks_box
  • (13)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete