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)

BirdOPrey5 12-23-2010 04:16 PM

Quote:

Originally Posted by azn_romeo_4u (Post 2138141)
How do you do this for arrays?



Like more than one forums.

Quote:

Originally Posted by popowich (Post 2138148)
Multiple usergroups, forums, etc syntax looks like :

<if condition="is_member_of($vbulletin->userinfo, 5,6,8)">

Actually that is_member_of is a function specific to usergroups...

In general to do this for arrays it would be:

Code:

<if condition="in_array($forum[forumid], array(2, 3, 4, 5, 6 ))">
and for !=

Code:

<if condition="!in_array($forum[forumid], array(2, 3, 4, 5, 6 ))">

AlexisMedia 12-25-2010 05:21 PM

I'm trying to find the conditional to include "in every forum except (several forums). I wasn't sure what the "!=" meant but I thought that might be it so I tried this but it was a no-go.

Code:

<vb:if condition="!in_array($foruminfo[forumid], array(26, 46 )">MyScript</vb:if>
Any ideas on how I could do that? Thanks!

I'm using vB4....

Lynne 12-25-2010 05:56 PM

Quote:

Originally Posted by AlexisMedia (Post 2138959)
I'm trying to find the conditional to include "in every forum except (several forums). I wasn't sure what the "!=" meant but I thought that might be it so I tried this but it was a no-go.

Code:

<vb:if condition="!in_array($foruminfo[forumid], array(26, 46 )">MyScript</vb:if>
Any ideas on how I could do that? Thanks!

I'm using vB4....

That may not be a valid variable to use in that template. What template are you trying to put it in (take a look at the template itself and see what variable is being used there).

(Also, this is a vB3 article, although most of the conditions are valid, but in vB4 it does matter what template you use a variable in.)

AlexisMedia 12-25-2010 06:02 PM

I was using it in the same FORUM DISPLAY template that we changed that variable to fix. Sorry I posted in the vB3 article. I didn't realize it till after I had done it but then figured it was still my best chance because the post just before seemed to relate.

I tried posting in my other thread but it did that auto-merge again : (

(but I see you found it anyways...LOL.)

BirdOPrey5 12-25-2010 09:50 PM

The VB4 version of this thread is here. I don't want to talk about VB4 in a VB3 thread. If you're still having issues please post in the VB4 thread for help.

AlexisMedia 12-26-2010 12:02 AM

Yes, I apologize. I didn't realize it when I first typed my post... Then I left it.

Moving on...

nikki712 02-03-2011 01:15 PM

I want to exclude the forums listed below. But when I use this conditional, I get an error. What am I doing wrong? I'm running 3.8.6 PL1

Code:

<if condition="$forum[forumid] != 1,2,3,4">google ad code here</if>
It's not working.

I get the error:

Code:

The following error occurred when attempting to evaluate this template:

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

This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish.

How can I fix this? Is the fact that I run vbseo a problem?

I'd also like to exclude certain usergroups from seeing ads. How do I accomplish both of these things?

BirdOPrey5 02-03-2011 01:48 PM

What's wrong is your condition is wrong... it should look like this:

Code:

<if condition="!in_array($forum['forumid'], array(1,2,3,4))"></if>

nikki712 02-03-2011 01:52 PM

Thanks! Is there a way to use two conditionals? I don't want ads showing up in certain forums, and there's on particular usergroup that I want to block ads from. Is this possible?

BirdOPrey5 02-03-2011 02:34 PM

Code:

<if condition="!in_array($forum['forumid'], array(1,2,3,4)) AND !is_member_of($vbulletin->userinfo, 5,6)">
That won't show it in forums 1, 2, 3, or 4 and won't show it to anyone in usergroups 5 or 6.

nikki712 02-03-2011 03:07 PM

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>


BirdOPrey5 02-03-2011 03:18 PM

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

nikki712 02-03-2011 03:28 PM

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.

BirdOPrey5 02-03-2011 04:42 PM

Quote:

Originally Posted by nikki712 (Post 2158277)
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.

nikki712 02-03-2011 04:53 PM

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.

BirdOPrey5 02-03-2011 04:59 PM

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.

nikki712 02-03-2011 07:06 PM

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!

BirdOPrey5 02-03-2011 08:13 PM

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?

nikki712 02-03-2011 10:29 PM

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.

PAKIDIL 02-28-2011 02:12 PM

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

genxstan 05-17-2011 09:00 AM

Can somebody tell me how to hide code tags with something else for unregistered users using if conditional statement?

BirdOPrey5 05-17-2011 10:16 AM

You need to edit your bbcode templates, such as the template: bbcode_code

Put the entire template in a template conditional- something like:

Code:

<if condition="$show[member]">

original template code here

<else />
You must be logged in to view this code.
</if>

Do this for all the code templates you want (CODE, PHP, HTML) and their associated "print" templates as well otherwise people can see them if they go to print the page.

genxstan 05-18-2011 05:15 PM

Quote:

Originally Posted by BirdOPrey5 (Post 2196728)
You need to edit your bbcode templates, such as the template: bbcode_code

Put the entire template in a template conditional- something like:

Code:

<if condition="$show[member]">

original template code here

<else />
You must be logged in to view this code.
</if>


Do this for all the code templates you want (CODE, PHP, HTML) and their associated "print" templates as well otherwise people can see them if they go to print the page.

Thanks for the help mate :)

Curious Too 09-03-2011 04:19 PM

I have an ad that I want to show to one particular social group. This is the code I tried but it didn't work:

if condition="$groups[groupid] == X
if condition="$group[groupid] == X
if condition="$grps[groupid] == X

Are there any conditionals for social groups?

BirdOPrey5 09-03-2011 07:02 PM

Quote:

Originally Posted by Curious Too (Post 2241581)
I have an ad that I want to show to one particular social group. This is the code I tried but it didn't work:

if condition="$groups[groupid] == X
if condition="$group[groupid] == X
if condition="$grps[groupid] == X

Are there any conditionals for social groups?

$group[groupid] is what is used throughout the groups.php script. If that isn't working it probably isn't available in the template you are trying to use it on- where are you trying these conditionals?

The only other possibility would be to try
Code:

$vbulletin->GPC[groupid]
so
Code:

<if condition="$vbulletin->GPC[groupid] == x">

Curious Too 09-03-2011 07:14 PM

I'm trying to use it in the ad location template ad_navbar_below. This didn't work either:

<if condition="$vbulletin->GPC[groupid] == x">

BirdOPrey5 09-03-2011 09:11 PM

Yeah I looked through the code, this just isn't going to be possible with a template conditional. For who knows what reason the people who programmed social groups did not make them behave like forums and threads which would have been logical.

Curious Too 09-03-2011 10:25 PM

Thank you for trying to help.

|Jordan| 01-13-2012 06:41 AM

I'm trying to make a conditional that will display in all forums except 8 forums,

Quote:

<if condition="$show['newthreadlink'] && $forum['forumid'] != 6,7,8,9,22,23,24,25">
Is this syntax right?

HMBeaty 01-13-2012 07:13 AM

Quote:

Originally Posted by |Jordan| (Post 2287188)
I'm trying to make a conditional that will display in all forums except 8 forums,



Is this syntax right?

Close. It should be....
HTML Code:

<if condition="$show['newthreadlink'] && !in_array($forum['forumid'], array(6,7,8,9,22,23,24,25))">

|Jordan| 01-13-2012 08:22 PM

Thanks for the fix, but it doesnt work :( I changed the code to make testing have less variables

Quote:

<if condition="$show['newthreadlink'] && $forum['forumid'] == 8"><a href="complaints-suggestions.php" rel="nofollow"><img src="$stylevar[imgdir_button]/newthread.gif" alt="$vbphrase[post_new_thread]" border="0" /></a><else /><a href="newthread.php?$session[sessionurl]do=newthread&amp;f=$foruminfo[forumid]" rel="nofollow"><img src="$stylevar[imgdir_button]/newthread.gif" alt="$vbphrase[post_new_thread]" border="0" /></a></if>
I applied it to forumdisplay and the new thread button still displays with the default newthread url even in the forum i dont want it to display in.

HMBeaty 01-14-2012 02:47 AM

Try this: (sometimes && doesn't doesn't play well in templates)
HTML Code:

<if condition="$show['newthreadlink'] AND $forum['forumid'] == 8">
    <a href="complaints-suggestions.php" rel="nofollow"><img src="$stylevar[imgdir_button]/newthread.gif" alt="$vbphrase[post_new_thread]" border="0" /></a>
<else />
    <a href="newthread.php?$session[sessionurl]do=newthread&amp;f=$foruminfo[forumid]" rel="nofollow"><img src="$stylevar[imgdir_button]/newthread.gif" alt="$vbphrase[post_new_thread]" border="0" /></a>
</if>


TheLastSuperman 01-14-2012 04:36 AM

Quote:

Originally Posted by HMBeaty (Post 2287518)
Try this: (sometimes && doesn't doesn't play well in templates)
HTML Code:

<if condition="$show['newthreadlink'] AND $forum['forumid'] == 8">
    <a href="complaints-suggestions.php" rel="nofollow"><img src="$stylevar[imgdir_button]/newthread.gif" alt="$vbphrase[post_new_thread]" border="0" /></a>
<else />
    <a href="newthread.php?$session[sessionurl]do=newthread&amp;f=$foruminfo[forumid]" rel="nofollow"><img src="$stylevar[imgdir_button]/newthread.gif" alt="$vbphrase[post_new_thread]" border="0" /></a>
</if>


OR

HTML Code:

<if condition="$show['newthreadlink'] AND $thread['forumid'] == 8">
    <a href="complaints-suggestions.php" rel="nofollow"><img src="$stylevar[imgdir_button]/newthread.gif" alt="$vbphrase[post_new_thread]" border="0" /></a>
<else />
    <a href="newthread.php?$session[sessionurl]do=newthread&amp;f=$foruminfo[forumid]" rel="nofollow"><img src="$stylevar[imgdir_button]/newthread.gif" alt="$vbphrase[post_new_thread]" border="0" /></a>
</if>

Replacing $forum with $thread but I believe either should work fine it's vB4 that does not get along with $forum being used within showthread and other if I'm remembering correctly so why we use thread in that situation.

|Jordan| 01-14-2012 05:02 AM

Quote:

Originally Posted by HMBeaty (Post 2287518)
Try this: (sometimes && doesn't doesn't play well in templates)
HTML Code:

<if condition="$show['newthreadlink'] AND $forum['forumid'] == 8">
    <a href="complaints-suggestions.php" rel="nofollow"><img src="$stylevar[imgdir_button]/newthread.gif" alt="$vbphrase[post_new_thread]" border="0" /></a>
<else />
    <a href="newthread.php?$session[sessionurl]do=newthread&amp;f=$foruminfo[forumid]" rel="nofollow"><img src="$stylevar[imgdir_button]/newthread.gif" alt="$vbphrase[post_new_thread]" border="0" /></a>
</if>


That didnt work either :(

@TheLastSuperman, this is for VB3.

BirdOPrey5 01-14-2012 10:00 AM

If you search the template you are putting the custom code in, look at what variable names are already being used.

In showthread $forum is never used... Nor is $thread, the actual one used is $threadinfo.

In forumdisplay it's $foruminfo....

So for the forumdisplay template this would be the code:

PHP Code:

<if condition="$show['newthreadlink'] AND $foruminfo['forumid'] == 8">
    <
a href="complaints-suggestions.php" rel="nofollow"><img src="$stylevar[imgdir_button]/newthread.gif" alt="$vbphrase[post_new_thread]border="0" /></a>
<else />
    <
a href="newthread.php?$session[sessionurl]do=newthread&amp;f=$foruminfo[forumid]rel="nofollow"><img src="$stylevar[imgdir_button]/newthread.gif" alt="$vbphrase[post_new_thread]border="0" /></a>
</if> 


|Jordan| 01-14-2012 07:20 PM

OMG THAT WORKED!

Thank you Thank you! THANK YOU!

kpmedia 03-24-2012 09:14 AM

Quote:

Originally Posted by nquang (Post 2083497)
Is there a variable for which member create thread??

Late reply, but had the same question myself. (At least I think it's the same question.)
Looked in the db, read some docs, and got it right on the first try. :)

Code:

<if condition="$thread[postuserid] == 15">
CODE
</if>

Where "15" is the user in the code example.

Code added to the template could show a message to members/guests (unless further limited by more conditionals), in posts created by this specific thread starter. For example, to add a unique secondary signature by an admin in new threads. You can hard code the message, or add a new phrase variable.

###

ttaspinar 04-03-2012 03:46 PM

thanks.

MRGTB 06-10-2012 09:43 AM

Quote:

Originally Posted by BirdOPrey5 (Post 2138153)
Actually that is_member_of is a function specific to usergroups...

In general to do this for arrays it would be:

Code:

<if condition="in_array($forum[forumid], array(2, 3, 4, 5, 6 )">
and for !=

Code:

<if condition="!in_array($forum[forumid], array(2, 3, 4, 5, 6 )">

Your missing an extra closing bracket there.

Code:

<if condition="in_array($forum[forumid], array(2, 3, 4, 5, 6 ))">
and for !=

Code:

<if condition="!in_array($forum[forumid], array(2, 3, 4, 5, 6 ))">

BirdOPrey5 06-10-2012 11:08 AM

Thanks. Updated original post. :up:


All times are GMT. The time now is 10:45 AM.

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

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04834 seconds
  • Memory Usage 1,877KB
  • 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
  • (21)bbcode_code_printable
  • (5)bbcode_html_printable
  • (1)bbcode_php_printable
  • (13)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
  • (40)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