XF 1.4 How to insert ads into forum list and thread list?

jeffwidman

Active member
There are three places I'd like to stick ads, but I can't seem to figure out the right conditionals for:

1) on the forum list page, I'd like to insert ads before and after some specific forum categories.
Looks like I need to edit the "forum_list" template. I can't figure out which pieces of code refer to the category containers, but I want something like:

If category = 2 or 4, insert ad
<category container code>
If category = 2 or 4, insert ad

2) On the thread list page within a forum, I'd like to insert ads after every Nth thread.

3) On the New Posts page, I'd like to insert ads after every Nth thread

No idea for the last two which template/conditional to use...
 
1) on the forum list page, I'd like to insert ads before and after some specific forum categories.
Looks like I need to edit the "forum_list" template. I can't figure out which pieces of code refer to the category containers, but I want something like:

If category = 2 or 4, insert ad
<category container code>
If category = 2 or 4, insert ad
I don't have a lot of time right now, but as for your first question, the below information should solve your problem:
HTML:
How can I show content in a specific category?
<xen:if is="{$category.node_id} == x">
This content will show in category x
</xen:if>
Note that in order for this to work, you must have categories set as pages in the ACP -> Options -> Node & Forum List: Create Pages for Categories.
Additionally, to ensure the category ID is available in the ad_ templates, the category_view template must be edited and the following code added: <xen:container var="$category.node_id">{$category.node_id}</xen:container>
There's a great XenForo syntax conditional statement resource available! You will meed to use <xen:if is="{$category.node_id} == x OR {$categoryy.node_id} == y"> for working with enabling it in multiple categories only. I believe that there's a more simplified manner using arrays, but I'd need to test it just to make sure.

As for inserting ads every Nth post, the resource also has some information on this, but you'd need to make some slight modifications. (The below is directly from the resource)
HTML:
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == x">
This content will show after post x on every page
</xen:if>
 
Thanks.

For the category, I found this post by the ever helpful @Jake Bunce that seems like a more concise solution: https://xenforo.com/community/threads/banner-on-the-middle-categories.34850/#post-395748

For the threads--I did check out the conditional resource multiple times and didn't find what I'm looking for.

I'm not trying to put an ad every Nth post, I'm trying to put an ad between every Nth thread on pages that are a list of threads--for example, within specific forums and the new posts page.

I suspect the code is similar, I'm just not sure how to change the variables to "thread position" instead of "post position" and "thread per page" instead of "messages per page".

I'm also not sure exactly which templates need to be changed, but I can probably figure that out through trial and error, it's the variables that are primarily tripping me up.
 
Last edited:
Top Bottom