Ad after absolute first post and only in threads

CyberAP

Well-known member
#1
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?
 

Brogan

XenForo moderator
Staff member
#2
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.
 

estranged

Well-known member
#4
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?
 

estranged

Well-known member
#6
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>
 

swatme

Well-known member
#7
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
 

Jake Bunce

XenForo moderator
Staff member
#8
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.
 

Jake Bunce

XenForo moderator
Staff member
#9
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>
 

DaveL

Well-known member
#10
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}"
 
#11
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!
 

Brogan

XenForo moderator
Staff member
#12
Rich (BB code):
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND {$thread.reply_count} > 0">
Change the thread reply count to suit.
 
Top