Ad after absolute first post and only in threads

CyberAP

Well-known member
I have a code to insert an ad after first post but it also inserts ad in conversations and it doesn't depend on the thread page.

Here is my code:
PHP:
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0">
<xen:include template="my_ad" />
</xen:if>

How can I exclude conversations from this and show this only on the first page of the thread?
 
This should do it.

Code:
<xen:if is="{$post.position} == 0 AND !{$message.conversation_id}">
Content
</xen:if>

Most of the commonly used conditionals are in the FAQ linked to in my signature.
I've got a big update planned so I'll add in the conversation one when I do.
 
I am trying to show the ads only in/after first post to everybody expect usergroup 5. But I couldn't manage to do it. Seems like I can't combine <xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0"> with <xen:if is="!{xen:helper ismemberof, $visitor, 5}"> I've tried various combinations so far but doesn't work.

Any ideas?
 
Thank you! I'm using this currently and finally it works.

Code:
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND !{$message.conversation_id} AND !{xen:helper ismemberof, $visitor, 5}">
ad code
</xen:if>
 
ok second post ads is working here

Code:
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 1">
text ads here
</xen:if>

now i want to make it appear in the last post
whats the condition?

thanks
 
ok second post ads is working here

Code:
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 1">
text ads here
</xen:if>

now i want to make it appear in the last post
whats the condition?

thanks

You can use the ad_thread_view_below_messages template. That template already places the code after the last post without any special condition.

Otherwise this is the condition:

Code:
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == {$xenOptions.messagesPerPage} - 1">
text ads here
</xen:if>

However, this condition doesn't always match the last post on a page. It won't match the last post on a thread page that isn't "full". For example, a thread with 15 posts and 10 posts per page would only match the last post on the first page.
 
Otherwise this is the condition:

Code:
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == {$xenOptions.messagesPerPage} - 1">
text ads here
</xen:if>

However, this condition doesn't always match the last post on a page. It won't match the last post on a thread page that isn't "full". For example, a thread with 15 posts and 10 posts per page would only match the last post on the first page.

Scratch that. Here is a condition that works for the last post on every page in a thread:

Code:
<xen:if is="({$post.position} % {$xenOptions.messagesPerPage} == {$xenOptions.messagesPerPage} - 1 OR {$post.position} == {$thread.reply_count})">
text ads here
</xen:if>
 
Thank you! I'm using this currently and finally it works.

Code:
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND !{$message.conversation_id} AND !{xen:helper ismemberof, $visitor, 5}">
ad code
</xen:if>

Using this code, how would I add additional usergroups so they cannot see the add? I tried
Code:
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND !{$message.conversation_id} AND !{xen:helper ismemberof, $visitor, 5,3}">
ad code
</xen:if>

but that didnt work.

EDIT - sorted! I needed to add "AND !{xen:helper ismemberof, $visitor, 1}"
 
Sorry to resurrect an old thread, but I'm struggling with trying to figure out a variation of this conditional. I want to put an ad after the first post on every page, but only if there are X number of posts in the thread. Any help is appreciated.

Thanks!
 
Rich (BB code):
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND {$thread.reply_count} > 0">

Change the thread reply count to suit.
 
Again six years later, I'm also sorry to bring this up. The answer to my question is already here, but I'm just too dumb to know where I should put this code, in oder to make it work?
This should do it.

Code:
<xen:if is="{$post.position} == 0 AND !{$message.conversation_id}">
Content
</xen:if>

Most of the commonly used conditionals are in the FAQ linked to in my signature.
I've got a big update planned so I'll add in the conversation one when I do.

In which template do I have to add this code? (I tried extra.css)

Code:
<xen:if is="{$post.position} == 0 AND !{$message.conversation_id}">
<xen:include template="http://website.com/ad.htm" />
</xen:if>

And the "template" I'm trying to load is a simple html file

Code:
<html>
<head>
<title>Ad</title>
</head>
<a href="https://www.youtube.com/channel/UCiRjDPTj8RzrS8846HOQ-Yg" target="_blank"><img src="https://i.imgur.com/hhZvDYg.jpg" border="0"></a> 
</body>
</html>
 
Thank you SO much, for you quick replies.

As the thread starter said, I'd like to have the ad shown under the first post in thread view:
1608306281165.png

Is that: ad_thread_view_below_messages ?
Or which template?

Edit: I found it: https://xenforo.com/community/resources/visual-list-of-ad-locations.1383/

I wish you a wonderful Holiday season - you're doing an outstanding job!
And is my "template" I posted above going to work? In displaying a static image with a link?
 
I've got it to work...somehow :)

Code:
<xen:hook name="ad_thread_view_below_messages" />
<xen:if is="{$post.position} == 0 AND !{$message.conversation_id}">
<xen:include template="http://site.com/test/ad.htm" />
</xen:if>

I think I'm still doing something wrong :(
The ad.htm look like this:

Code:
<html>
<head>
<title>Ad</title>
</head>
<a href="https://www.youtube.com/channel/UCiRjDPTj8RzrS8846HOQ-Yg" target="_blank"><img src="https://i.imgur.com/hhZvDYg.jpg" border="0"></a>
</body>
</html>
 
Last edited:
Just put the ad code directly in place of <xen:include template="http://site.com/test/ad.htm" />.

Otherwise, if you have created a custom ad template in the XF template system, use <xen:include template="name_of_template" />.
 
Top Bottom