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

How do I display ads only to certain users?

Discussion in 'XenForo Questions and Support' started by Jaxel, Jan 2, 2011.

  1. Jaxel

    Jaxel Well-Known Member

    Lets say I have a premium membership upgrade path with usergroup 5. If someone purchases premium membership, they will automatically join secondary usergroup 5. Inside of a TEMPLATE, how would I check to see if a user is part of this group? Basically I want to do something like:

    Code:
    <xen:if is="!is_member($visitor, '5')">
    AD CODE
    </xen:if>
     
  2. Shadab

    Shadab Well-Known Member

    steven s likes this.
  3. kingston

    kingston Well-Known Member

  4. Lawrence

    Lawrence Well-Known Member

    Have you tried adding the ! right after the first " as shown below?

    HTML:
    <xen:if is="!{xen:helper ismemberof, $visitor, 5}">
    	<!-- content -->
    </xen:if>
     
  5. kingston

    kingston Well-Known Member


    <xen:if is="{$post.position} == 0 AND !{$visitor.user_id}">

    is what I currently have. That should only show the google ads (what is the conditional) to visitors, correct?

    I want to say if they arent a member of my paid for group (No Ads that is part of the pay for update system) show the ads.
     
  6. Lawrence

    Lawrence Well-Known Member

    in the message template (at the very bottom) for your style, try this:

    HTML:
    <xen:if is="!{$post.position} AND !{$visitor.user_id}">
    
        <xen:if is="!{$message.conversation_id}">
    code for Ad here....  Remove $message.conversation_id IF statement if you want ads shown after 1st message of a PC as well.
    
        </xen:if>
    
    </xen:if>
    
     
  7. kingston

    kingston Well-Known Member

    First, thanks for your help!

    Second, what if I want to show to everyone BUT the admin group and those that paid to upgrade? Groups 3 and 20
     
  8. Lawrence

    Lawrence Well-Known Member


    If you know the group id's and they are their primary group ids, then this will work for you (it's the simplest for your case):

    HTML:
    <xen:if is="!{$post.position} AND !{$visitor.is_admin} AND {$visitor.user_group_id} != '20'">
    
        <xen:if is="!{$message.conversation_id}">
    code for Ad here....  Remove $message.conversation_id IF statement if you want ads shown after 1st message of a PC as well.
    
    
        </xen:if>
    
    </xen:if>
     
     
    Young likes this.
  9. kingston

    kingston Well-Known Member


    Does that group have to be a primary group? is there a way to do it for additional groups?
     
  10. Lawrence

    Lawrence Well-Known Member

    Yip, for addition groups that is where the newly added helper will come in. I haven't played with the ismemberof helper, but this should work (I just tested this quickly):

    HTML:
    <xen:if is="!{$post.position} AND !{$visitor.is_admin} AND !{xen:helper ismemberof, $visitor, 20}">
    
        <xen:if is="!{$message.conversation_id}">
    code for Ad here....  Remove $message.conversation_id IF statement if you want ads shown after 1st message of a PC as well.
    
    
        </xen:if>
    
    </xen:if>
      
     
  11. kingston

    kingston Well-Known Member


    Perfecta! Now just figure how to have google ads post after the 1st post on a page and im set! haha
     
  12. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    !{post.position} already does that. Or if you want to display ads after the first post on every page then use this.

    Code:
    <xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND !{$visitor.is_admin} AND !{xen:helper ismemberof, $visitor, 20}">
    
        <xen:if is="!{$message.conversation_id}">
    code for Ad here....  Remove $message.conversation_id IF statement if you want ads shown after 1st message of a PC as well.
    
    
        </xen:if>
    
    </xen:if>
    
     

Share This Page