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

Template Conditionals - Front Page Banner Ads

Discussion in 'XenForo Questions and Support' started by akia, Oct 17, 2011.

  1. akia

    akia Well-Known Member

    I'm trying to set up some banner ads for my site but the problem I'm having is a leader board dosn't fit on the front page under the top bread crumbs, and a normal size banner looks odd when just viewing a thread etc.

    Is there a Template Conditional that I can wrap my ad code up in so that if someone is on the home page it displays one ad code and if elsewhere it displays another.
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Code:
    <xen:if is="{$contentTemplate} == 'forum_list'">
    	HOMEPAGE
    <xen:else />
    	ALL OTHER PAGES
    </xen:if>
    
     
    akia likes this.
  3. akia

    akia Well-Known Member

    Thank you! :)
     
  4. akia

    akia Well-Known Member

    Can you Nest If tags within each other?

    Currently I've got:

    Code:
    <xen:if is="{$contentTemplate} == 'forum_list'">
    <xen:if is="{$visitor.user_id}">
    <div style="text-align: center; margin-top:8px;">
    <script type='text/javascript'><!--// <![CDATA[
        OA_show(1);
    // ]]> --></script>
    </div>
    <xen:else />
    <div style="text-align: center; margin-top:8px;">
    <script type='text/javascript'><!--// <![CDATA[
        OA_show(2);
    // ]]> --></script>
    </div>
    </xen:if>
    <xen:else />
    <xen:if is="{$visitor.user_id}">
    <div style="text-align: center; margin-top:8px;">
    <script type='text/javascript'><!--// <![CDATA[
        OA_show(1);
    // ]]> --></script>
    </div>
    <xen:else />
    <div style="text-align: center; margin-top:8px;">
    <script type='text/javascript'><!--// <![CDATA[
        OA_show(2);
    // ]]> --></script>
    </div>
    </xen:if>
    </xen:if>
    Will this work
     
  5. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Yes you can nest xen:if tags. That will work.
     
    akia likes this.
  6. akia

    akia Well-Known Member

    If I wanted to change to instead of showing ads to all members to just members of certain user groups what would I use?
     
  7. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

  8. Andy.N

    Andy.N Well-Known Member

    Let me piggy back on this thread as well.
    I load javascript for a media player in page_container_js_head.
    Code:
    <script type="text/javascript" src="/jwplayer/jwplayer.js"></script>
    However, this player is mostly used for a private node which majority of our members will not see and need to load.

    Which condition I should use to load this JS only under node id = x or category id = y?

    Thanks Jake ;)
     
  9. akia

    akia Well-Known Member

  10. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    You need to pass the node_id using xen:container. Edit these two templates:

    Admin CP -> Appearance -> Templates
    > forum_view
    > thread_view


    Add this line to the top of each template:

    Code:
    <xen:container var="$forumId">{$forum.node_id}</xen:container>
    
    Now you can use this condition for your javascript:

    Code:
    <xen:if is="{$forumId} == 2">
    
    </xen:if>
    
     
    Andy.N likes this.
  11. Andy.N

    Andy.N Well-Known Member

    Awesome. Would this cover all childs of a node/forum? Or I have I explicitly use them like <xen:if is="{$forumId} == 2, 4,60, 45">
     
  12. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Explicit:

    Code:
    <xen:if is="in_array({$forumId}, array(1,2,3))">
    
    </xen:if>
    
     
    Andy.N likes this.
  13. Euroman

    Euroman Active Member

    Can you guys tell me why my adsense ads don't show on the front page of my forum?

    The same code works on other sites but just not here. I'm going crazy over this..

    Help :eek:
     
  14. Brogan

    Brogan XenForo Moderator Staff Member

    As we discussed in the conversation, the content received from Google is blank.

    You will need to speak to Google AdSense about this.
     
  15. Euroman

    Euroman Active Member

    I have a green light from Google and my adsense account is all good.

    That's why I don't get it... :confused:
     
  16. Euroman

    Euroman Active Member

    Code:
    <script type="text/javascript"><!--
    google_ad_client = "ca-pub-2340283517533441";
    /* mlm-forums */
    google_ad_slot = "8848259061";
    google_ad_width = 250;
    google_ad_height = 250;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    This is the code I use and why note add it to any xenforo forum and see if it works. If it does then we know we have a problem on my forum...
     
  17. RobParker

    RobParker Well-Known Member

    In case you're not aware, Adsense ads usually take a couple of hours to show up. They'll be blank until then.

    If you've waited more than a few hours ignore me.
     
  18. Euroman

    Euroman Active Member

    Hi Rob

    It's been on for 24 hours :eek:

    You are welcome to add my code to your forum just to see if it works
     

Share This Page