1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. This forum is for release discussion only. Discussions that do not relate specifically to the resource release should be discussed in another, more appropriate forum.
    Dismiss Notice
  3. 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

Discussion in 'Template Modifications [Archive]' started by yoghurtfarmer, Oct 12, 2010.

  1. yoghurtfarmer

    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!
     
  2. ArnyVee

    ArnyVee Well-Known Member

    Nice job! :)

    Thanks for sharing! :D
     
    Vilad likes this.
  3. dutchbb

    dutchbb Well-Known Member

    Thanks for writing.
     
    Vilad likes this.
  4. onthefly

    onthefly Active Member

    Well, that is awesome and so easy to do, xen rocks! :) Thanks for posting that, fellow canuck! ;)
     
    Vilad likes this.
  5. Dav

    Dav Active Member

    Thanks for this, it was very helpful :)
     
  6. steven s

    steven s Well-Known Member

    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. :)
     
  7. steven s

    steven s Well-Known Member

    Note: updating from b1 to b2 reverts PAGE_CONTAINER and forum_list.
    At least it did for me.
     
  8. yoghurtfarmer

    yoghurtfarmer Well-Known Member

    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>
    
     

    Attached Files:

    Numenorean7, Andrej, vuiver and 17 others like this.
  9. yoghurtfarmer

    yoghurtfarmer Well-Known Member

    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.
     
  10. kkm323

    kkm323 Well-Known Member

    i wish i can help
    is it possible to make it appear as the last post in a thread in every page
     
  11. yoghurtfarmer

    yoghurtfarmer Well-Known Member

    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.png
     
  12. Ray

    Ray Active Member

    What if I want to show ads to certain usergroups and or in forums?
     
  13. yoghurtfarmer

    yoghurtfarmer Well-Known Member

    <xen:if is="{$forum.node_id} == x"></xen:if>

    <xen:if is="{$visitor.user_group_id} == x"></xen:if>

    Edit: fixed a mistake.
     
    imspot, kilcher, kkm323 and 1 other person like this.
  14. PeterT

    PeterT Active Member

    This is extremely useful, thank you :cool:
     
  15. Ray

    Ray Active Member

    Would it be possible to display ads in the first post, as seen on dp forums?
     
  16. Dav

    Dav Active Member

    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?
     
  17. yoghurtfarmer

    yoghurtfarmer Well-Known Member

    Yes but I haven't gotten around to trying it personally. Try the one here: http://xenforo.com/community/threads/banner-in-template.5511/

    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.
     
  18. yoghurtfarmer

    yoghurtfarmer Well-Known Member

    I see that you posted a thread and Lawrence provided the answer :).

     
  19. kilcher

    kilcher Active Member

    What if I want to show ads to more than one usergroup?
     
  20. PoLiZe

    PoLiZe Well-Known Member

    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 -->
     

Share This Page