How to add an ads block after first post on every page?

Avensen

Member
Hello. It's easy to add an ad block using

Code:
<xen:if is="{$post.position} == 0">
...
</xen:if>

condition in message template. However, ad block will only be shown on the first page of thread.

Is there a condition to show an ad block after first post on every page of a thread?

Thanks!
 
Jake, I'm using this code in the new ad_message_body template and it works great. I have two questions that I was hoping you might be able to help with.

  1. I'd like to add a conditional so that the ad shows for visitors only. I've tried a few things, but having trouble getting it correct.
  2. Is there a way to make this ad show in the first, last post on every page.
Thanks!
 
Jake, I'm using this code in the new ad_message_body template and it works great. I have two questions that I was hoping you might be able to help with.

  1. I'd like to add a conditional so that the ad shows for visitors only. I've tried a few things, but having trouble getting it correct.
  2. Is there a way to make this ad show in the first, last post on every page.
Thanks!

Here is a new condition that does both of those things:

Code:
<xen:if is="({$post.position} % {$xenOptions.messagesPerPage} == 0 OR {$post.position} % {$xenOptions.messagesPerPage} == {$xenOptions.messagesPerPage} - 1) AND !{$visitor.user_id}">
	AD CODE HERE
</xen:if>

This can be used in the ad_message_body template. It will show your ad code in the first and last post on each page of the thread, and only for guests.
 
Here is a new condition that does both of those things:

Code:
<xen:if is="({$post.position} % {$xenOptions.messagesPerPage} == 0 OR {$post.position} % {$xenOptions.messagesPerPage} == {$xenOptions.messagesPerPage} - 1) AND !{$visitor.user_id}">
	AD CODE HERE
</xen:if>

This can be used in the ad_message_body template. It will show your ad code in the first and last post on each page of the thread, and only for guests.

This would be ideal for me and others. I'm seeing an ad in the first post, but there are no ads populating the last post on the page. I'm still under the Google imposed 3 ads per page.
 
It works fine in my testing.

Check the source code of the page to see if the ad code is there. The code might not be rendering anything on the page.

It seems to work when there are sufficient posts to fill a thread. For example, it won't put ads in the second placement if there are only two posts in a thread. If it has two pages of posts, then it appears in the first and last position. Is this correct or should I check how I've implemented your code? Thanks again for your help.
 
It seems to work when there are sufficient posts to fill a thread. For example, it won't put ads in the second placement if there are only two posts in a thread. If it has two pages of posts, then it appears in the first and last position. Is this correct or should I check how I've implemented your code? Thanks again for your help.

Another option would be to put the ad just before the quick reply box, As explained Here

*EDIT
Just noticed you have obviously already seen that thread
 
It seems to work when there are sufficient posts to fill a thread. For example, it won't put ads in the second placement if there are only two posts in a thread. If it has two pages of posts, then it appears in the first and last position. Is this correct or should I check how I've implemented your code? Thanks again for your help.

Oh that's true. My code only fills the last position if it's a complete page of posts.

I think there is a condition for the last post on the page. I will look for that later.
 
Oh that's true. My code only fills the last position if it's a complete page of posts.

I think there is a condition for the last post on the page. I will look for that later.

Awesome. Thanks so much. Slowly filling any gaps from my previous life in vB. (actually still have more than a handful of vB sites still)
 
I can't find a condition for the last post on the page.

An alternative is to omit the "last post" from your ad code condition, like so:

Code:
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND !{$visitor.user_id}">
	AD CODE HERE
</xen:if>

Then use the ad_thread_view_below_messages template for your "last post" advertisement.
 
I can't find a condition for the last post on the page.

An alternative is to omit the "last post" from your ad code condition, like so:

Code:
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND !{$visitor.user_id}">
AD CODE HERE
</xen:if>

Then use the ad_thread_view_below_messages template for your "last post" advertisement.

Thanks again Jake. This was so helpful. In some ways, it might be more effective. I'm able to put a an ad 145 pixels out, so it actually looks somewhat like the next post in the thread. Should be interesting to see clickthrough rates.
 
Hi i want to add it to the first and last but i cant get i working
This does not work at all
Code:
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 or {$post.position} % {$xenOptions.messagesPerPage} == -1">

and this way it adds the 2nd advert to the first and second post :/
Code:
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 or {$post.position} % {$xenOptions.messagesPerPage} -1">

Maybe anyone can help me getting it working just to the 1. and last Post on every page?! Cheers
 
Well, i´ve got it working but´s not really what i want.
I also use ad_below_content
If i add another Code to ad_thread_view_below_messages it pushes out the Adsense from ad_below_content. Also the Adsense from ad_thread_view_below_messages is to far at the bottom. Best would be to tell the code in ad_message_below to be displayed in first and last but it seems that this is not possible ;) Thanks Jake
 
You don't need any xen:if when editing the ad_thread_view_below_messages template. That template already places the code after the last post without any special condition.
 
Hey @Jake Bunce

I'm currently using this code to position an ad after the first post in a thread:
Code:
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND !{$visitor.user_id}">
</xen:if>

I also have an ad in ad_thread_view_below_messages, however, when I have a thread with only one post, I end up with two ads, one right after the other, and I'm worried this will anger the Google gods....

Is there a way to modify the conditional so that if a thread only has one post, the middle ad, the one displayed under the first post, is not generated at all?
 
I use this:

<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND {$thread.reply_count} > 0">

So just add the last condition to your statement:

Code:
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND !{$visitor.user_id} AND {$thread.reply_count} > 0">
 
I use this:

<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND {$thread.reply_count} > 0">

So just add the last condition to your statement:

Code:
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND !{$visitor.user_id} AND {$thread.reply_count} > 0">

Perfect, that works exactly as I'd hoped! Thanks!
 
Top Bottom