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

XF 1.5 Adsense in the first post within the content

Neutral Singh

Well-known member
How can I show adsense within first and/or last post of every page like this: The message should seamlessly adjust along the sides of the adsense block...

adsense left.jpg adsense right.jpg
Last edited:


Well-known member
Hi @Neutral Singh

As a starting point..

Place it in ad_message_body template:

Then wrap using a template conditional:

First post:
<xen:if is="{$post.position} == 0 AND !{$message.conversation_id}">
or Last post:
<xen:if is="{$post.position} == {$thread.reply_count}">
You'll probably need to use CSS to float the ad to the right too. Maybe others can help too - have not placed an ad in that position before.

Neutral Singh

Well-known member
Thank you!

To show adsense block on every page, i used the following code:

<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND !{$message.conversation_id}">
Can't figure out how to show adsense on the last post of every page.

So, i have reached this stage:

adsense now 1.jpg

Now, how can i twist the CSS to show the block as desired in my first post.

adsense right.jpg

Thank you