• This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

Adding advertisements with template edits

yoghurtfarmer

Well-known member
Update: Thread has been updated with instructions for in post advertisements: see this post.

1. Create a template for each ad you will place.
I recommend this over placing the code directly in PAGE_CONTAINER or forum_list because it's much more manageable if you ever need to edit or change your ad. Xenforo also has a spectacular feature of showing which other templates have been included when you view a template.

On my site http://www.forumvancouver.com/, I have 3 ads at the moment. The bolded names are the template names I chose.

Top Leaderboard (adsense_top) - Above top breadcrumb and below navbar
Wide Sidetower (adsense_tower) - On the sidebar at the bottom
Bottom Leaderboard (adsense_bottom) - Above bottom breadcrumb

2. Fill in the template with your ad code along with any conditions and CSS.
For instance in adsense_top I have the following. The margin is to ensure that the search box doesn't overlap the ad when the window is resized smaller.
Code:
<div style="text-align: center; margin-top:8px;">
    GOOGLE ADSENSE CODE GOES HERE
</div>


For adsense_bottom, I only want them to be shown to guests, so I put everything in between <xen:if is="!{$visitor.user_id}"></xen:if>
Code:
<xen:if is="!{$visitor.user_id}">
    <div style="text-align: center;  padding: 7px;">
        GOOGLE ADSENSE CODE GOES HERE
    </div>
</xen:if>


3. Use the include function to place your ads in the appropriate template/spot
Place <xen:include template="TEMPLATE NAME" /> where you want your ad to be.

In the template PAGE_CONTAINER:
For adsense_top, I placed it immediately BEFORE​
<xen:if is="{$showUpgradePendingNotice}">

For adsense_bottom, I placed it immediately BEFORE​
<div class="breadBoxBottom">

In the template forum_list:
For adsense_tower, I placed it immediately BEFORE​
</xen:sidebar>

Note that the way I've done this incorporates adsense_tower only on the main page and the leaderboards to EVERY page on the forum.

There are likely more conditions that you can add to limit what type of page the ads show up on, so if you figure them out, do share!
 
Pretty cool.
Instead of my adsense being at the bottom of the page, it is ending up on the side, below the tower template.

Added: Nevermind, I think. Once I added the actual code, it seems to be working.

Now to read more tips and tricks. :)
 
Advertisement after the first post
I've included three variants that you can choose from. First, follow these general steps:
  1. In the template called message add to the end:
    Code:
    <xen:include template="adsense_post" />
  2. Create a new template called adsense_post
  3. Fill adsense_post with code from one of the three variants, replace placeholders with your own information where necessary.
Note: If you want the ad to be shown to everybody (not just guests), change <xen:if is="{$post.position} == 0 AND !{$visitor.user_id}"> to <xen:if is="{$post.position} == 0">


I haven't extensively tested this and only got it to recently work. Credits to najaru since his post helped me figure this out. His method didn't quite work for me (ads appeared every second post) but it laid the ground work for what I have written here.

-------------------------------------------------------------------------------------------

Ads appear without user information
Code:
<xen:if is="{$post.position} == 0 AND  !{$visitor.user_id}">
    <li class="message">

        <div class="messageUserInfo"></div>

        <div class="messageInfo primaryContent">
            <div class="messageContent">
                <blockquote class="messageText ugc baseHtml">
                    GOOGLE ADSENSE CODE GOES HERE
                </blockquote>
            </div>
        </div>
    </li>
</xen:if>


Ads appear posted by a fake user
Code:
<xen:if is="{$post.position} == 0 AND !{$visitor.user_id}">
    <li class="message">

        <div class="messageUserInfo">
            <div class="messageUserBlock">
                <div class="avatarHolder"><span class="avatar  av2m"><img  src="http://a3.twimg.com/profile_images/1090883135/xf_reasonably_small.png"  width="96px" height="96px"></span></div>

                <h3 class="userText">
                    Google
                    <em class="userTitle" itemprop="title">Adsense</em>
                </h3>

                <span class="arrow"><span></span></span>
            </div>
        </div>

       <div class="messageInfo primaryContent">
            <div class="messageContent">
                <blockquote class="messageText ugc baseHtml">
                    GOOGLE ADSENSE CODE GOES HERE
                </blockquote>
            </div>
           </div>
       </li>
</xen:if>


Ads appear posted by thread starter
Code:
<xen:if is="{$post.position} == 0 AND !{$visitor.user_id}">
    <li class="message">

        <xen:include template="message_user_info">
            <xen:map from="$message" to="$user" />
        </xen:include>

        <div class="messageInfo primaryContent">
            <div class="messageContent">
                <blockquote class="messageText ugc baseHtml">
                    GOOGLE ADSENSE CODE GOES HERE
                </blockquote>
            </div>
         </div>
    </li>
</xen:if>
 

Attachments

  • same user.webp
    same user.webp
    38 KB · Views: 380
  • no user.webp
    no user.webp
    33.9 KB · Views: 369
  • Fake User.webp
    Fake User.webp
    35.6 KB · Views: 369
If anyone can figure out how to get it to appear after the first post on every page (instead of just the first page), let me know.
 
Fixed a missing <div> closing tag which caused all subsequent posts to shift to the right on Safari. Also removed messageID, conditionals and data-author from <li> tag since duplicate IDs were causing validation errors and the extra stuff is extraneous for our purposes.

safarishift.webp
 
Hi,

Is there a way to stop the advertisement appearing in the second post of the conversation thread when you start a conversation with someone?
 
Would it be possible to display ads in the first post, as seen on dp forums?
Yes but I haven't gotten around to trying it personally. Try the one here: http://xenforo.com/community/threads/banner-in-template.5511/

Hi,

Is there a way to stop the advertisement appearing in the second post of the conversation thread when you start a conversation with someone?
Interesting, didn't come across that because I don't show those ads to members. I'm not all that familiar with conditionals, but there might be one that would prevent that from happening. By the way, could you remove the quote from your post since it's a bit of an eye-sore.
 
I see that you posted a thread and Lawrence provided the answer :).

Appearance -> Templates -> Message

Scroll down to the very bottom of the message template and paste in the following:

Code:
<xen:if is="!{$post.position} AND !{$message.conversation_id}">

your adsense code here

</xen:if>
 
In the sidebar

sidebar_online_users


In the final add:

HTML:
<!-- here start the adsence code -->

<div class="section">
<div class="secondaryContent">
<h3> Adsense </h3>
<div style="text-align: center; margin-top:8px;">

GOOGLE ADSENSE HERE
</div>
</div></div>

<!-- here finish the adsence code -->
 
Top Bottom