Conditional Statements for XenForo 2

Conditional Statements for XenForo 2

Watched by who?

I don't know if there's a way to do that. You can exclude usergroups, pages, and other conditions but I don't even know what the variable is that indicates how many members are watching a thread. Sorry.
 
Number the posts from "0" on the page (thread starter) so post "5" would be "4". like this:

Code:
<xf:if is="$post.position % $xf.options.messagesPerPage == 0">
<div style="text-align:center;">

{your code}

</div>  
</xf:if>

For after 8th post:

<xf:if is="$post.position % $xf.options.messagesPerPage == 7">

For after 18th post:

<xf:if is="$post.position % $xf.options.messagesPerPage == 17">
Thanks for the information but didn't work the way I wanted.

What I need is: Adsense in thread or post but should be in the first or second paragraph of the thread or post.

Example thread or post: blablabla information advert banner blalabla information.

I just need the ad to be part of the thread after few sentences.

Thanks.
 
Apologies if this has been covered. I have read much of this thread, but admit I don't understand most of it.

I am trying to prevent adsense from showing in one thread that Google doesn't like. I have a few ad units showing there but I will start with this one:

<xf:if is="$xf.reply.template == 'thread_view' AND {$__globals.forum.node_id} != 2">

What is wrong with this code? It seems to block ALL thread_view not just the thread_view in thread ID 2.
 
If you have access to $thread, you should be able to use this code:

Code:
<xf:if is="$thread && $thread.thread_id != 123">
   Show content..
</xf:if>

123 is your thread id.

I am trying to hide the ad in only one thread. How would I combine that with this:

<xf:if is="$xf.reply.template == 'thread_view'">
 
I assume my code is sufficient, but you can add $template == 'thread_view':

Code:
<xf:if is="$template == 'thread_view' && $thread && $thread.thread_id != 123">
   Show content..
</xf:if>
 
I am trying to hide the ad in only one thread. How would I combine that with this:

<xf:if is="$xf.reply.template == 'thread_view'">
Try the following condition in the advertisement HTML code:

HTML:
<xf:if is="$xf.reply.contentKey != 'thread-123'">
Your ad code here.
</xf:if>

Note: {{dump($xf)}} is your friend.
 
Was not trying to be ungrateful!

So I can just add your line?

Here is my whole code. I need to block this thread view ad, from thread number 2.

<code>

<xf:if is="$xf.reply.template == 'thread_view'">
<div class="advertising-wide">
<div style="margin-top:0px;margin-bottom:8px;">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- fixed 728x90 -->
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-XXXXX"
data-ad-slot="XXXXX"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
</div>
<div class="advertising-narrow">
<div style="margin-top:0px;margin-bottom:8px;">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- fixed 320x100 -->
<ins class="adsbygoogle"
style="display:inline-block;width:320px;height:50px"
data-ad-client="ca-pub-XXXXXXX"
data-ad-slot="XXXXX"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
</div>
</xf:if>

</code>
 
Try following in the advertisement HTML code:

Never worked with the XF core "ads" feature. Does my code not work in that case? i.e. no access to $template and $thread?

@Harvey: I guess you should replace <xf:if is="$xf.reply.template == 'thread_view'"> with <xf:if is="$xf.reply.contentKey != 'thread-123'"> (123 == thread_id), like suggested by @smozgur.
 
Was not trying to be ungrateful!
Oh, I didn't mean something bad :) I love the dump function so much, so I always mention that in template variable questions.

I assume you are entering the ad code in the Advertisement module. So, when the ad code is rendered, I don't think $thread variable object is passed to the ad template, so we need to use $xf.reply, as you also figured out.

The $xf.reply.contentKey contains a "thread-XXX" string if a thread is displayed, otherwise null. If you just use the condition I posted to wrap your ad code, by providing the thread ID in place of XXX, then it should work without problems to hide the ad only for that thread.
 
I guess you should replace <xf:if is="$xf.reply.template == 'thread_view'"> with <xf:if is="$xf.reply.contentKey != 'thread-123'">
.. or in your case I assume you want:

<xf:if is="$xf.reply.template == 'thread_view' && $xf.reply.contentKey != 'thread-123'">.

Sorry for confusion!
 
You don't even need to check @xf.reply.template since contentKey should work fine. Like this (replace XXX with that particular thread ID)

HTML:
<xf:if is="$xf.reply.contentKey != 'thread-XXX'">

<div class="advertising-wide">
<div style="margin-top:0px;margin-bottom:8px;">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- fixed 728x90 -->
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-XXXXX"
data-ad-slot="XXXXX"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
</div>
<div class="advertising-narrow">
<div style="margin-top:0px;margin-bottom:8px;">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- fixed 320x100 -->
<ins class="adsbygoogle"
style="display:inline-block;width:320px;height:50px"
data-ad-client="ca-pub-XXXXXXX"
data-ad-slot="XXXXX"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
</div>
</xf:if>
 
So I can just add your line?
Note: If you are using the page-level cache, then you'll need to wait until the page cache is flushed. I mention this because it took me some time, in the beginning, to realize why my guest template changes were not working.
 
Yes I am using the ADVERTISING section of the ACP


My code (above) is repeated three times starting with these different lines:

<xf:if is="$xf.reply.template == 'forum_list'">
<xf:if is="$xf.reply.template == 'forum_view'">
<xf:if is="$xf.reply.template == 'thread_view'">

so I need to do it 3 times.

I don't know what kind of cache-ing I am using but it is a problem for me. I thought I had solved this problem and then a few hour later all my ads disappeared.
 
<xf:if is="$xf.reply.template == 'thread_view' && $xf.reply.contentKey != 'thread-123'">

This works!

Now I have two other places I need to execute this, as I have 3 different ad units that show on that page.

This is for and ad I use in our "universal" footer. Here I need to prohibit ads from running in one forum (Admin private forum) and that one thread Google doesn't like:

<xf:if is="in_array($xf.reply.template, ['forum_list', 'forum_view', 'thread_view', 'thread_view_type_poll', 'whats_new', 'whats_new_posts'])">
 
The final place I need to prohibit ads is in my "Ad Below Post" in an add-on by Andy. Code is here:

<xf:css src="andy_adbelowpost.less" />

<center>
<div class="advertising-wide">
<div style="margin-top:10px; margin-bottom:10px;">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- XF 728 Ad Below Post -->
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-XXXXXX"
data-ad-slot="XXXXXX"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
</div>
<div class="advertising-narrow">
<div style="margin-top:10px;margin-bottom:10px;">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- XF 320 Ad Below Post -->
<ins class="adsbygoogle"
style="display:inline-block;width:320px;height:100px"
data-ad-client="ca-pub-XXXXXX"
data-ad-slot="XXXXXX"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
</div>
</center>
 
<xf:if is="in_array($xf.reply.template, ['forum_list', 'forum_view', 'thread_view', 'thread_view_type_poll', 'whats_new', 'whats_new_posts'])">

just a little change:

<xf:if is="in_array($xf.reply.template, ['forum_list', 'forum_view', 'thread_view', 'thread_view_type_poll', 'whats_new', 'whats_new_posts']) && $xf.reply.contentKey != 'thread-123'">.

Note: I just added && $xf.reply.contentKey != 'thread-123'.

The final place I need to prohibit ads is in my "Ad Below Post" in an add-on by Andy. Code is here:

Same as above. You should wrap the whole code block with:

Code:
<xf:if is="$xf.reply.template == 'thread_view' && $xf.reply.contentKey != 'thread-123'">
// Your existing Code
</xf:if>

But I think if you have more specific questions, you should create a new thread for this.

Edit: oh, it's an addon template.. So maybe my first try will work here:

Code:
<xf:if is="$template == 'thread_view' && $thread && $thread.thread_id != 123">
   Show content..
</xf:if>
 
<xf:if is="in_array($xf.reply.template, ['forum_list', 'forum_view', 'thread_view', 'thread_view_type_poll', 'whats_new', 'whats_new_posts']) && $xf.reply.contentKey != 'thread-123'">.
This works!

If I want block both a forum that thread how? No luck with this:
<xf:if is="in_array($xf.reply.template, ['forum_list', 'forum_view', 'thread_view', 'thread_view_type_poll', 'whats_new', 'whats_new_posts']) && $xf.reply.contentKey != 'thread-123' && $xf.reply.contentKey != 'node-456'">.

<xf:if is="$template == 'thread_view' && $thread && $thread.thread_id != 123"> Show content.. </xf:if>
If I entered this ^^ correctly, it blocks all ads not just the one intended.
 
Top Bottom