XF 2.0 How to display ADs only in threads of particular forums ?

Surendra.S

Active member
Hi All,

How to display content only in threads of particular forums ?

For eg, I want to display ADs only in the threads that belong to one of these forums with Node Ids - 4 or 6 or 8

I tried to create an Advertisement with code below, but it does not seem to work.

Code:
<xf:if is="in_array({$thread.node_id}, [4,6,8])">
Place AD Code here
</xf:if>

Please help.
 

tearvt

Active member
I don't know the ID's of your threads because they are individual for your forum. Go to the thread in which you want to display your AD and take the number from the URL.

Example:
187892

My Thread ID would be '2'. My code would therefore look like this:
Code:
<xf:if is="in_array({$thread.thread_id}, [2])">
My Advertisement
</xf:if>
 

tearvt

Active member
I got your point now. Use this condition to show your ad in specific forums:
Code:
<xf:if is="in_array({$forum.node_id}, [4,6,8])">
Your advertisement...
</xf:if>
 

Surendra.S

Active member
Thank You so much @Chris D . That's working.

Just to make things clear for others looking for the same, I am giving the crux of my requirement.

Requirement: I want to display ADVERTISEMENT inside only the threads that belong to one of these forums with Node Ids - 4 or 6 or 8 (for example)


AD Position: Post: Above message content


The code I tried (and did NOT work) :

Code:
<xf:if is="in_array({$forum.node_id}, [4,6,8])">
    Place AD Code here
</xf:if>


The code that worked :

Code:
<xf:if is="in_array($post.Thread.node_id, [4,6,8])">
    Place AD Code here
</xf:if>
 

chris TFF

Member
I am trying to do something similar in the header to pass NodeID and ThreadID to Google DFP for it to set the adverts.

Node ID is working but threadID isn't. I have tried loads of variations. Any ideas?

Code:
            <xf:if is="{$forum.node_id}">
                <!-- Forum ID: {$forum.node_id} -->
                googletag.pubads().setTargeting("Forum_ID","{$forum.node_id}");
            </xf:if>
          
            <xf:if is="{$thread.thread_id}">
                <!-- THREAD ID: {$thread.thread_id} -->
                googletag.pubads().setTargeting("THREAD_ID","{$thread.thread_id}");
            </xf:if>
 

Syn9

Member
Same here, tried numerous combinations and checked the XF2 Conditionals resource for the {$thread.thread_id} template syntax but found nothing yet.

I ran across this post that mentions using the following template syntax but it's not working for me:
Code:
<xf:if is="$context.thread.thread_id == x">
Would be grateful for any help, as I'm trying to selectively display ads based on Thread ID's in an array.
 
Last edited:
Top