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

How to add an ads block after first post on every page?

Discussion in 'XenForo Questions and Support' started by Avensen, Dec 25, 2010.

  1. Avensen

    Avensen Member

    Hello. It's easy to add an ad block using

    Code:
    <xen:if is="{$post.position} == 0">
    ...
    </xen:if>
    condition in message template. However, ad block will only be shown on the first page of thread.

    Is there a condition to show an ad block after first post on every page of a thread?

    Thanks!
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Use this condition:

    Code:
    <xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0">
    ...
    </xen:if>
    
     
    Big Dan, AnthonyT, Young and 2 others like this.
  3. Avensen

    Avensen Member

    Thanks Jake, worked like a charm!
     
  4. cmeinck

    cmeinck Well-Known Member

    Jake, I'm using this code in the new ad_message_body template and it works great. I have two questions that I was hoping you might be able to help with.

    1. I'd like to add a conditional so that the ad shows for visitors only. I've tried a few things, but having trouble getting it correct.
    2. Is there a way to make this ad show in the first, last post on every page.
    Thanks!
     
  5. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Here is a new condition that does both of those things:

    Code:
    <xen:if is="({$post.position} % {$xenOptions.messagesPerPage} == 0 OR {$post.position} % {$xenOptions.messagesPerPage} == {$xenOptions.messagesPerPage} - 1) AND !{$visitor.user_id}">
    	AD CODE HERE
    </xen:if>
    
    This can be used in the ad_message_body template. It will show your ad code in the first and last post on each page of the thread, and only for guests.
     
    cmeinck likes this.
  6. cmeinck

    cmeinck Well-Known Member

    This would be ideal for me and others. I'm seeing an ad in the first post, but there are no ads populating the last post on the page. I'm still under the Google imposed 3 ads per page.
     
  7. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    It works fine in my testing.

    Check the source code of the page to see if the ad code is there. The code might not be rendering anything on the page.
     
  8. cmeinck

    cmeinck Well-Known Member

    It seems to work when there are sufficient posts to fill a thread. For example, it won't put ads in the second placement if there are only two posts in a thread. If it has two pages of posts, then it appears in the first and last position. Is this correct or should I check how I've implemented your code? Thanks again for your help.
     
  9. Brett Peters

    Brett Peters Well-Known Member

    Another option would be to put the ad just before the quick reply box, As explained Here

    *EDIT
    Just noticed you have obviously already seen that thread
     
  10. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Oh that's true. My code only fills the last position if it's a complete page of posts.

    I think there is a condition for the last post on the page. I will look for that later.
     
  11. cmeinck

    cmeinck Well-Known Member

    Awesome. Thanks so much. Slowly filling any gaps from my previous life in vB. (actually still have more than a handful of vB sites still)
     
  12. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    I can't find a condition for the last post on the page.

    An alternative is to omit the "last post" from your ad code condition, like so:

    Code:
    <xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND !{$visitor.user_id}">
    	AD CODE HERE
    </xen:if>
    
    Then use the ad_thread_view_below_messages template for your "last post" advertisement.
     
  13. cmeinck

    cmeinck Well-Known Member

    Thanks again Jake. This was so helpful. In some ways, it might be more effective. I'm able to put a an ad 145 pixels out, so it actually looks somewhat like the next post in the thread. Should be interesting to see clickthrough rates.
     
  14. bogus

    bogus Guest

    Hi i want to add it to the first and last but i cant get i working
    This does not work at all
    Code:
    <xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 or {$post.position} % {$xenOptions.messagesPerPage} == -1">
    and this way it adds the 2nd advert to the first and second post :/
    Code:
    <xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 or {$post.position} % {$xenOptions.messagesPerPage} -1">
    Maybe anyone can help me getting it working just to the 1. and last Post on every page?! Cheers
     
  15. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

  16. bogus

    bogus Guest

    Well, i´ve got it working but´s not really what i want.
    I also use ad_below_content
    If i add another Code to ad_thread_view_below_messages it pushes out the Adsense from ad_below_content. Also the Adsense from ad_thread_view_below_messages is to far at the bottom. Best would be to tell the code in ad_message_below to be displayed in first and last but it seems that this is not possible ;) Thanks Jake
     
  17. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    You don't need any xen:if when editing the ad_thread_view_below_messages template. That template already places the code after the last post without any special condition.
     
  18. CivilWarTalk

    CivilWarTalk Active Member

    Hey @Jake Bunce

    I'm currently using this code to position an ad after the first post in a thread:
    Code:
    <xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND !{$visitor.user_id}">
    </xen:if>
    
    I also have an ad in ad_thread_view_below_messages, however, when I have a thread with only one post, I end up with two ads, one right after the other, and I'm worried this will anger the Google gods....

    Is there a way to modify the conditional so that if a thread only has one post, the middle ad, the one displayed under the first post, is not generated at all?
     
  19. Brogan

    Brogan XenForo Moderator Staff Member

    I use this:

    <xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND {$thread.reply_count} > 0">

    So just add the last condition to your statement:

    Code:
    <xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND !{$visitor.user_id} AND {$thread.reply_count} > 0">
     
    Jake Bunce likes this.
  20. CivilWarTalk

    CivilWarTalk Active Member

    Perfect, that works exactly as I'd hoped! Thanks!
     

Share This Page