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

Ad after absolute first post and only in threads

Discussion in 'XenForo Questions and Support' started by CyberAP, Mar 20, 2011.

  1. CyberAP

    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?
     
  2. Brogan

    Brogan XenForo Moderator Staff Member

    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.
     
    Coop1979 and CyberAP like this.
  3. CyberAP

    CyberAP Well-Known Member

    Thanks! Worked like a charm!
     
  4. estranged

    estranged Well-Known Member

    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?
     
  5. Brogan

    Brogan XenForo Moderator Staff Member

    Try this:

    <xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND !{xen:helper ismemberof, $visitor, 5}">
     
    estranged likes this.
  6. estranged

    estranged Well-Known Member

    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>
     
  7. swatme

    swatme Well-Known Member

    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
     
  8. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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.
     
  9. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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>
    
     
    Bram likes this.
  10. DaveL

    DaveL Well-Known Member

    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. moleculo

    moleculo Member

    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!
     
  12. Brogan

    Brogan XenForo Moderator Staff Member

    Code:
    <xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND {$thread.reply_count} > 0">
    Change the thread reply count to suit.
     
  13. moleculo

    moleculo Member

    Sweet, thanks!
     

Share This Page