XF 1.5 How to show ad above last message on each page

island

Active member
I'd like to show a horizontal ad above the last post on each page of a thread. I thought I had it figured out using:

Code:
<xen:if is="!{$visitor.user_id} AND {xen:number $thread.reply_count} > 2 AND !in_array({$thread.thread_id}, array(9998,9999))">
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == {$xenOptions.messagesPerPage} - 2 OR {$post.position} == {$thread.reply_count} - 1 AND !{$message.conversation_id}">
Ad Code
</xen:if>
</xen:if>
This seems to work perfectly 99% of the time, but I'm noticing a few anomalies:

  • On one 5-page thread, an extra ad is shown on page 4.
    A horizontal ad is showing correctly above the last post on pages 1-3, but then on page 4 there are two ads, one above and one below the last post. I'm not sure why page 4 is getting 2 ads. Page 5 has only one reply and shows no ad. There was a deleted post on page 1, I don't know if this has any impact. (Edit: permanently deleted the 1 deleted post in the thread instead of just removed from public view, and no change, so maybe math error because the last page has one post???)

  • On one long 56-page thread, there is simply no horizontal ad shown at all. The threadID is not 9998 or 9999. I can't figure out why the above is ruling out this thread... The thread link is /threads/thread-title.629/ and 629 is not in the array (9998,9999)

    Edit: Correction -- it appears on this one thread, it's the {xen:number $thread.reply_count} > 2 that is not showing an ad when present, even though there are hundreds of replies to that thread ?

    Edit2:
    appears this point is solved by changing

    AND {xen:number $thread.reply_count} > 2
    to
    AND {$thread.reply_count} > 2

    For some reason the only thread that didn't seem to work with the {xen:number $thread.reply_count} > 2 conditional was the 56-page thread in question (there may be others, but I didn't find another...) Not sure if it was based on the number of pages or something about the particular thread... but changing it to {$thread.reply_count} > 2 as the conditional now works... curious...
Any ideas?
 
Last edited:
OK, better way to do it was to create a new template
ad_message_above

Include ad_message_above template above post area in template
message

Then change conditional to simply
<xen:if is="!{$visitor.user_id} AND {$thread.reply_count} > 2 AND !in_array({$thread.thread_id}, array(9998,9999))">
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == {$xenOptions.messagesPerPage} OR {$post.position} == {$thread.reply_count} AND !{$message.conversation_id}">
 
Correction to above: parenthesis needed for consistent operation

<xen:if is="!{$visitor.user_id} AND {$thread.reply_count} > 2 AND !in_array({$thread.thread_id}, array(9998,9999))">
<xen:if is="({$post.position} % {$xenOptions.messagesPerPage} == {$xenOptions.messagesPerPage} OR {$post.position} == {$thread.reply_count}) AND !{$message.conversation_id}">
 
Back
Top Bottom