• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.4 How to restrict adsense code to certain section?

garry420

Active member
#1
I have few questions which i need for my forum

How to restrict adsense code to certain section of forum ?
Reason: I will add news to this section.

I want my ads to show up just 3 times in thread but everytime someone comments it starts showing up .
someone please guide me which is the best place to post adsense code in and how to do it ?

regards
 

Tracy Perry

Well-known member
#4
So do I.. but that guide is easy enough to understand.
And what do you mean "show up 3 times in thread"? Do you mean after the first post, then the second post and finally the third post? You need to be more precise in what you are asking about.
I use the ad_message_below template myself.

You could probably use the
Code:
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == x">
This content will show after post x on every page
</xen:if>
code. If wanting it after set posts, then use this instead of a single number (which is what the x represents) replace it with an array.

Code:
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == array(y, z)">
This content will show after post y and z on every page
</xen:if>
where y,z are the post numbers. You can do additional by just using x,y,z format.

Now, if you are wanting it to only show in once specific forum this will probably work


Code:
<xen:if is="{$forum.node_id} == x">
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == array(y, z)">
This content will show after post y and z on every page
</xen:if>
</xen:if>
Where X is the actual forum node ID number.

The only problem is, if you use ad_message_below then you will only be showing the ads on that one forum, unless you do additional if/then statements.
 
Last edited:

garry420

Active member
#5
So do I.. but that guide is easy enough to understand.
And what do you mean "show up 3 times in thread"? Do you mean after the first post, then the second post and finally the third post? You need to be more precise in what you are asking about.
I use the ad_message_below template myself.
I mean every-time someone replies or ads comment, one ad starts showing with theta added reply/comment.
 

Tracy Perry

Well-known member
#6
I mean every-time someone replies or ads comment, one ad starts showing with theta added reply/comment.
ad_below_message will add an ad below every post (not conversation)... but doing it below every post will - if you are using adsense - quickly put you in violation of their TOS.
You could do it after the 2nd, 5th and 8th post or something similar.

I've given you an example above to try. Without knowing more (exact) details of the node ID # and what posts you want it after exactly then further help is going to be limited.
 
Last edited:

garry420

Active member
#7
ad_below_message will add an ad below every post (not conversation)... but doing it below every post will - if you are using adsense - quickly put you in violation of their TOS.
You could do it after the 2nd, 5th and 8th post or something similar.

I've given you an example above to try. Without knowing more (exact) details of the node ID # and what posts you want it after exactly then further help is going to be limited.
I m confused..hence i am planning to create a widget at side bar. but i dono how to do that. can you guide me ?
i mean widget in sidebar where in i can put adsense code
you can check my forum from my signature, and please guide me to do better..:)
 

Tracy Perry

Well-known member
#8
I m confused..hence i am planning to create a widget at side bar. but i dono how to do that. can you guide me ?
i mean widget in sidebar where in i can put adsense code
you can check my forum from my signature, and please guide me to do better..:)
There are templates in the ACP -> Appearance -> Templates that allow you to control where ads are placed using the default sidebar. If you are using BD Widgets, then you will need to use one that renders one of the ad-templates for you or create your own template.

Screen Shot 2015-03-01 at 9.32.56 AM.png

In your original posts you were wanting ads in the posts/comments area, now you are talking about the sidebar.
The only way I know to "guide you better" is to actually do it. I've given you template examples that you can modify to work for you in the posts.
The sidebar will be similar -but depends on whether you are using BD Widgets or the built in stuff. Another option may be @Audentio Design new Ad Manager.
 

garry420

Active member
#9
what if i want to place adsense code within certain content in forum post , is that possible ?
If yes how if no what should i do to get bit more revenue ?
 

Brogan

XenForo moderator
Staff member
#12
There are guides in my signature for conditional statements and AdSense.

The exact code required will depend on where and how you want to place it.