The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
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> -------------------------- 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 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 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'); HTML Code:
<if condition="THIS_SCRIPT == 'index'"></if> HTML Code:
<if condition="THIS_SCRIPT != 'index'"></if> -------------------------- 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> HTML Code:
<if condition="$bbuserinfo['userid'] != 667"></if> -------------------------- 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> HTML Code:
<if condition="$forum[forumid] != X"></if> HTML Code:
<if condition="in_array($forum['forumid'], array(1,2,3,6))"></if> -------------------------- If the user is a member of the x usergroup then show the code. HTML Code:
<if condition="$post['usergroupid'] == 6"></if> HTML Code:
<if condition="$post['usergroupid'] != 6"></if> -------------------------- 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> HTML Code:
<if condition="$bbuserinfo['birthday_search'] < '1980-01-01'">Too Young</if> -------------------------- 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> HTML Code:
<if condition="$thread['forumid'] != X"></if> HTML Code:
<if condition="in_array($thread['forumid'], array(1,2,3,6))"></if> -------------------------- If the user is a moderator execute code. HTML Code:
<if condition="can_moderate()"></if> -------------------------- If the user is a moderator of the current forum execute code. HTML Code:
<if condition="can_moderate($forum['forumid'])"></if> -------------------------- If the user is a moderator of x forum execute code. HTML Code:
<if condition="can_moderate($forum['x'])"></if> -------------------------- Is the user the thread creator? If so execute code. HTML Code:
<if condition="$threadinfo['postuserid'] == $bbuserinfo['userid']"></if> -------------------------- If the thread is closed execute code. HTML Code:
<if condition="!$show['closethread']"></if> -------------------------- Useful for adding a advertisement or other information after the first post on every page. HTML Code:
<if condition="!$GLOBALS['FIRSTPOSTID']"></if> -------------------------- 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> -------------------------- 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> |
#52
|
|||
|
|||
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> |
#53
|
||||
|
||||
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). |
#54
|
|||
|
|||
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. |
#55
|
||||
|
||||
Quote:
|
#56
|
|||
|
|||
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. |
#57
|
||||
|
||||
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. |
#58
|
|||
|
|||
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> 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! |
#59
|
||||
|
||||
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? |
#60
|
|||
|
|||
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)"> 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> --------------- 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. |
#61
|
|||
|
|||
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 ?. |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|