XF 2.2 Show ads on first, 7th and last post

masmo

Member
Sorry, I know... there are many discussions about it but I can't find what I need.

At the moment I am using this solution:

I wish the ads were more dynamic...
OK for the one ads on every first post but if the last post is the 5th, the ads is not displayed.
Is there a way to calculate the last post and if there isn't already a banner add it?
Thanks
 
Solution
You can likely use elseif:

HTML:
<xf:if is="...">
   <!-- ad 1 -->
<xf:elseif is="..." />
    <!-- ad 2 -->
<xf:elseif is="..." />
    <!-- ad 3 -->
</xf:if>
Depending on your ad setup, you may want to look into: https://xenforo.com/community/resources/ads-manager-2-lite-by-siropu.7002/

It makes life easier when it comes to ads. Can target specific posts, rotate ad banners in various spots, conditionals for all sorts of things such as usergroups, devices, pages, and a ton more. Something to consider.

As for the conditional, maybe something like this? Check if there are a certain amount of posts:
 
Just a little help...
This seems to work:
Code:
<xf:if is="$post.position % $xf.options.messagesPerPage == 0">
Ads 1
</xf:if>
<xf:if is="$post.position % $xf.options.messagesPerPage == 6">
Ads 2
</xf:if>
<xf:if is="$post.position == $xf.options.messagesPerPage - 1 OR $post.position % $xf.options.messagesPerPage + 1 == count($__globals.posts) AND count($__globals.posts) >= 3">
Ads 3
</xf:if>

How can I avoid having two banners in the 7th post?
I tried adding != 7 in the last rule but it doesn't work...
Thanks
 
You can likely use elseif:

HTML:
<xf:if is="...">
   <!-- ad 1 -->
<xf:elseif is="..." />
    <!-- ad 2 -->
<xf:elseif is="..." />
    <!-- ad 3 -->
</xf:if>
 
Solution
Thanks again Jeremy :D

This works perfectly:
Code:
<xf:if is="$post.position % $xf.options.messagesPerPage == 0">
Ad 1
<xf:elseif is="$post.position % $xf.options.messagesPerPage == 6" />
Ad 2
<xf:elseif is="$post.position == $xf.options.messagesPerPage - 1 OR $post.position % $xf.options.messagesPerPage + 1 == count($__globals.posts) AND count($__globals.posts) >= 3" />
Ad 3
</xf:if>
 
Back
Top Bottom