Conditional Statements

Conditional Statements

Veer

Well-known member
#41
@Brogan, I'm displaying an advertisement in ad_sidebar_below_visitor_panel template using the following code:
Code:
<xen:if is="{xen:helper ismemberof, $visitor, 1, 2, 3}">

Ad code here

</xen:if>
This ad is also displaying in Conversation sidebar. How to not display in Conversation pages?
 

EQnoble

Well-known member
#43
how to hide Replies if Replies =0
Edit template: thread_list_item

Find:
Code:
<dl class="major"><dt>{xen:phrase replies}:</dt> <dd>{xen:if $thread.isRedirect, '&ndash;', {xen:number $thread.reply_count}}</dd></dl>
Replace with:
Code:
<xen:if is="{xen:number $thread.reply_count} != 0">
    <dl class="major"><dt>{xen:phrase replies}:</dt> <dd>{xen:if $thread.isRedirect, '&ndash;', {xen:number $thread.reply_count}}</dd></dl>
</xen:if>
edited
 
Last edited:
#44
Hello
Show this banner in all pages in forum but do not show it in all threads!
Code:
<xen:if is="!{$contentTemplate} == 'thread_view'">
Banner
</xen:if>
Is it right?
Thanx
 

Sola

Active member
#46
To NOT DISPLAY ads in SOME categories while letting ads show everywhere else, is this HOW-TO? (using the built in templates)?
Trying to keep Google out of the threads in TWO Categories.
Thanks for any assistance.

Code:
<xen:hook name="ad_above_top_breadcrumb" />
<xen:if is="{$forum.node_id} == 14">
<xen:if is="{$forum.node_id} == 37">
<xen:if is="{$forum.node_id} == 2">
<xen:if is="{$forum.node_id} == 102">
<xen:if is="{$forum.node_id} == 30">
<xen:if is="{$forum.node_id} == 97">
<xen:if is="{$forum.node_id} == 80">
<xen:if is="{$forum.node_id} == 97">
<xen:if is="{$forum.node_id} == 105">
<xen:if is="{$forum.node_id} == 35">
<xen:if is="{$forum.node_id} == 8">
<xen:if is="{$forum.node_id} == 65">
<center>

<style>
.asynch-top { width: 320px; height: 50px; }
@media(min-width: 500px) { .asynch-top { width: 468px; height: 60px; } }
@media(min-width: 800px) { .asynch-top { width: 728px; height: 90px; } }
</style>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- asynch_top -->
<ins class="adsbygoogle asynch-top"
    etc.,etc.,etc.</ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</center></xen:if></xen:if></xen:if></xen:if></xen:if></xen:if></xen:if></xen:if></xen:if></xen:if></xen:if></xen:if>
 

Sola

Active member
#51
Is anyone else willing to help me with this? Haven't had ads on my site for close to three months now. My pocket is feeling it.
I thought I was asking in the right place - under conditionals. But that doesn't seem to be the case now...
A link perhaps?
'Pprecaite it.
 

EQnoble

Well-known member
#52
This means, if is not forum node id1 or id5 then do ADSENSE
Code:
<xen:if is="!in_array({$forum.node_id}, array(1, 5))">
ADSENSE
</xen:if>
Just replace ADSENSE with what you want to appear there when not either of those two nodes which you also change to suit.
 

Sola

Active member
#53
Okay, found this also by the Moderator, in the post here for anyone else looking.
On the page, he said
In the example above I have a few conditionals to stop adverts being displayed on a Page node (55) and to 5 user groups.
So, the first line below disables ads from a particular node/forum section, which would be what I'm looking for. Now, how to have multiple nodes disabled is the question. I suspect it going to be by using AND! as he did with the user groups restriction in the second row. Will play with it.

Code:
<xen:if is="{$quickNavSelected} != 'node-55'">
<xen:if is="!{xen:helper ismemberof, $visitor, 3} AND !{xen:helper ismemberof, $visitor, 4} AND !{xen:helper ismemberof, $visitor, 5} AND !{xen:helper ismemberof, $visitor, 6} AND !{xen:helper ismemberof, $visitor, 7}">
<div style="text-align: center">
<script type="text/javascript"><!--
google_ad_client = "your-adsense-id";
/* Banner Narrow (Above Upper Breadcrumb) */
google_ad_slot = "4545463";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
</xen:if>
</xen:if>
 

Sola

Active member
#55
Below is what works for me, just in case someone else gets lost like I did with the "array" jargon in the first line. Thanks again.
<xen:if is="!in_array({$forum.node_id}, array(2, 8))">

<xen:if is="!{xen:helper ismemberof, $visitor, 3} AND !{xen:helper ismemberof, $visitor, 7} AND !

{xen:helper ismemberof, $visitor, 14} AND !{xen:helper ismemberof, $visitor, 15} AND !{xen:helper

ismemberof, $visitor, 20} AND !{xen:helper ismemberof, $visitor, 13} AND !{xen:helper ismemberof,

$visitor, 2}">

ETC

</xen:if></xen:if>
 
Last edited:

rdn

Well-known member
#56
Simplified code for you @Sola
PHP:
<xen:if is="!in_array({$forum.node_id}, array(2, 8)) AND !{xen:helper ismemberof, $visitor, 2,3, 7,13,14,15,20}">
ETC
</xen:if>
 

Brogan

XenForo moderator
Staff member
#58
Okay, to be clear, it is this Resources section that you're referring me to, right?
No.

This actual resource: http://xenforo.com/community/resources/conditional-statements.1604/

When working with arrays, the ! is placed just before the argument.
For example, <xen:if is="in_array({$forum.node_id}, array(x, y, z))"> for true, <xen:if is="!in_array({$forum.node_id}, array(x, y, z))"> for false.
How can I show content to more than one member?
<xen:if is="in_array({$visitor.user_id}, array(x, y, z))">
This content will show to members x, y and z
</xen:if>
How can I show content after post x on every page, only in forums y and z?
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == x AND in_array({$thread.node_id}, array(y, z))">
This content will show after post x on every page, only in forums y and z
</xen:if>
How can I show content after post x on every page, except in forums y and z?
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == x AND !in_array({$thread.node_id}, array(y, z))">
This content will show after post x on every page, except in forums y and z
</xen:if>
How can I show content in more than one forum?
<xen:if is="in_array({$forum.node_id}, array(x, y, z))">
This content will show in forums x, y, and z
</xen:if>
How can I show content in more than one thread?
<xen:if is="in_array({$threadId}, array(x, y, z))">
This content will show in threads x, y, and z
</xen:if>
How can I show content in more than one post?
<xen:if is="in_array({$postId}, array(x, y, z))">
This content will show in posts x, y, and z
</xen:if>
All the information and examples on using arrays.

There is also a specific resource on AdSense with several more examples using arrays: http://xenforo.com/community/resources/responsive-adsense.2084/
 

Breixo

Well-known member
#59
I'm using "Rotating Ads" addon to show ads to non-registered users.
But I'd like to avoid them at /login/ (so register/login is easier for them).

I tried this:
Code:
<xen:if is="{$contentTemplate} != 'thread_view'">
Code:
<xen:if is="{$contentTemplate} != 'login'">
But ads are still there. What I'm doing wrong?
Thanks!
 

Brogan

XenForo moderator
Staff member
#60
According to AdSense terms, adverts shouldn't be shown on login, error and various other pages anyway.

You should be using an array:
Code:
<xen:if is="!in_array({$contentTemplate}, array('error', 'search_form', 'search_form_post', 'search_form_profile_post', 'search_results', 'register_form', 'login', 'error_with_login'))">
 
Top