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

XF 2.0 Having trouble putting an ad after the first post

#1
With the new ad system, I am selecting "post: below message content". I can see that, by default, this puts an ad after every post.

Trying to just put the ad either after just the first post, or ideally, after the 1st, 10th, and last post. I had codes that worked in the past, but now I can't seem to get anything to work. Seems no matter what I try, the ad shows up after every post in the thread.

All the codes I used in the past seem to be useless now.
 

Brogan

XenForo moderator
Staff member
#2
You will still need to use conditional statements to only show after post x.

They will need to be rewritten for XF2 as the syntax has changed.
 
#3
You will still need to use conditional statements to only show after post x.

They will need to be rewritten for XF2 as the syntax has changed.
Thanks.

If anybody has done this already and willing to share, that would be greatly appreciated. I like having the ad in a couple of the posts, but definitely don't want them in every post.
 
#5
If you post the code you used previously I'll convert it for you.
Code:
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0">
adcode here
</xen:if>
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 1">
adcode here
</xen:if>
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == {$xenOptions.messagesPerPage} - 1 OR {$post.position} == {$thread.reply_count} AND {$thread.reply_count} % {$xenOptions.messagesPerPage} > 1">
adcode here
</xen:if>
The above one puts an ad into whatever the last post is.

Below is a more simpler code for three ads

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

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

<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 19">
</xen:if>
</xen:if>
These are the two I have been using for a while.
 

Chris D

XenForo developer
Staff member
#6
It's not a whole lot of difference:
HTML:
<xf:if is="$post.position % $xf.options.messagesPerPage == 0">
    <div style="text-align: center; padding: 10px;">
        <img src="https://storage.googleapis.com/support-kms-prod/SNP_501E7C3D5CA3CA07C641E6BAFB8A53C794CF_2922339_en_v2" />
    </div>
</xf:if>

<xf:if is="$post.position % $xf.options.messagesPerPage == 1">
    <div style="text-align: center; padding: 10px;">
        <img src="https://storage.googleapis.com/support-kms-prod/SNP_501E7C3D5CA3CA07C641E6BAFB8A53C794CF_2922339_en_v2" />
    </div>
</xf:if>

<xf:if is="$post.position % $xf.options.messagesPerPage == 19">
    <div style="text-align: center; padding: 10px;">
        <img src="https://storage.googleapis.com/support-kms-prod/SNP_501E7C3D5CA3CA07C641E6BAFB8A53C794CF_2922339_en_v2" />
    </div>
</xf:if>
Result:
1506269117430.png
The main differences are:
  • You don't need the user_id check, as there are checkboxes on the edit advertising page to show/hide the advert based on user groups (if you did, then the correct syntax would be $xf.visitor.user_id.
  • <xen: has become <xf:.
  • $xenOptions and some other "global" template params (like visitor) are now in the $xf namepace, e.g. $xf.options.
  • In some contexts, such as the conditions, you no longer need the curly braces.
Obviously the styling was thrown together, you might want to do something different.