XF 1.2 Advertisement in the new posts page

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?
 
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.
 
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.
 
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.
 
I shortly did the basic code and achieved something like this:
Untitled-3.webp

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.
 
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.
 
Top Bottom