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

XF 1.2 Advertisement in the new posts page

Discussion in 'Styling and Customization Questions' started by Dakis, Nov 14, 2013.

  1. Dakis

    Dakis Well-Known Member

    Back in the vb days, I was using an add-on to put an ad after the Xth result in the search results page and it worked really well as these pages get a lot of traffic. For xenForo we have two different pages now, "new posts" and "search results" page, .

    How can something similar be achieved in these two xenForo pages? There are no ad templates for those pages, so what should be the code/conditional that would have to go in these pages' templates to accomplish this?
     
  2. Jeremy

    Jeremy XenForo Moderator Staff Member

    Edit find_new_posts, modify this section of code:
    Code:
            <xen:foreach loop="$threads" value="$thread">
               
                <xen:if is="{$showingNewPosts} AND !{$_activityBarShown} AND {$thread.last_post_date} < {$session.previousActivity}">
                    <li class="discussionListItem"><div class="noteRow">{xen:phrase threads_below_not_been_updated_since_last_visit_have_unread}</div></li>
                    <xen:set var="$_activityBarShown">1</xen:set>
                </xen:if>
               
                <xen:include template="thread_list_item">
                    <xen:set var="$showForumLink">1</xen:set>
                    <xen:set var="$showLastPageNumbers">1</xen:set>
                </xen:include>
    
            </xen:foreach>
    
    You can modify the xen:foreach to set an index number so you can use a conditional to insert your advertisements. My xen:tag resource explains the xen:foreach tag and @Brogan's conditional contains most of the guidance you need.
     
    Dakis likes this.
  3. Dakis

    Dakis Well-Known Member

    Thanks I'll have a shot at it :)
     
  4. Dakis

    Dakis Well-Known Member

    Can someone help me with this? I've tried looking around these two resources but I still don't know what I'm doing :D

    Basically the goal is to edit this code above to place an ad code after the 5th result in the "new posts" and "search results" pages.
     
  5. Jeremy

    Jeremy XenForo Moderator Staff Member

    What have you tried?
     
  6. Dakis

    Dakis Well-Known Member

    I made a mess is what I've done. :D I'm not a developer so I only picked bits and pieces from that code and tried to replicate it within that loop, but I don't know how to set it to show up after a specific count of results for example.

    If it's too much of a fuss it's fine, I can ask someone for some services to get this done.
     
  7. Dakis

    Dakis Well-Known Member

    Is someone willing to do this as a paid service?
     
  8. katsulynx

    katsulynx Well-Known Member

    I shortly did the basic code and achieved something like this:
    Untitled-3.jpg

    In my example an advertisement is set after each fifth element but only if a sixth one will follow. To do this, you'll have to do the following

    If you have multiple styles, do the following:

    1. Set the forum to debug mode
    2. Open up the Template Modifications under Appearance->Styles & Templates -> Template Modifications and press "+Create Template Modification"
    3. As template, set "find_new_posts", as Modification Key, set something unique you will remember, set the Description as you like.
    4. Don't alter the Search Type
    5. For find, copy-paste the following code:
      HTML:
      <xen:foreach loop="$threads" value="$thread">
    6. And for replace this one:
      HTML:
      <xen:foreach loop="$threads" value="$thread" i="$i" count="$total">
                <xen:if is="{$i}%6 == 0">
                    YOUR ADVERTISEMENT CODE
                  </xen:if>
      You can do some modifications here. Of course you will need to replace the "YOUR ADVERTISEMENT CODE" with your advertisement code. If you want to show the advertisement after each Xth Element, replace "{$i}%6" with "{$i}%(X+1)", e.g. when you like it to be shown after each 10th post, set X+1 to 11 and therefor "{$i}%11".
    If you only have one style, don't set the forum to debug mode and go to Appearance->Styles->Your Style->Templates and search for "find_new_posts" and replace the first code line from above with the second code block. You can find it using the usual strg+f inside the code box.
     
    surfsup, RoldanLT and Dakis like this.
  9. Dakis

    Dakis Well-Known Member

    That's great! I will try it now. :)

    Edit: it's great thank you very much!
     
    Last edited: Jan 16, 2014
  10. Dakis

    Dakis Well-Known Member

    @katsulynx actually there is an issue with this code, it creates an ad EVERY 5 threads, while the idea is to create just one ad after the first 5 only. Any idea how to correct this? :)
     
  11. katsulynx

    katsulynx Well-Known Member

    Oh, got you wrong there. Replace
    Code:
    <xen:if is="{$i}%6 == 0">
    with
    Code:
    <xen:if is="{$i} == 6">
    to show an Ad between the fifth and sixth entry if there is a sixth. If you want it to be shown after the fifth even if there is not a sixth, we'll need to set up the modification a little bit different.
     
    Dakis likes this.
  12. Dakis

    Dakis Well-Known Member

    That works great, thanks. No need to modify it for only 5 results, this should be more than enough :)
     
  13. RoldanLT

    RoldanLT Well-Known Member

    This is not against Google TOS?
    Serving ads on search result itself?
     
  14. Bryan Gilchrist

    Bryan Gilchrist Active Member

    I believe that refers to displaying ads within Google search results, say if you had a custom Google search on your site.
     
    RoldanLT likes this.
  15. RoldanLT

    RoldanLT Well-Known Member

    OK :)
    I have applied this on the 2nd Row :)
     
    Last edited: Jan 17, 2014
  16. Bryan Gilchrist

    Bryan Gilchrist Active Member

    RoldanLT likes this.

Share This Page