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

Please help me get an If Then statement correct to block tabs for Guests

Discussion in 'XenForo Questions and Support' started by Jamie, Oct 31, 2010.

  1. Jamie

    Jamie Well-Known Member

    I have the shoutbox installed and since guests can't use it I would like to just hide the tab for anyone that can't use it.

    So what is the code I am looking for?

    <if guest>
    Show Guest menu
    <else />
    Show Member menu
    </if>


    Thanks!
    Jamie
     
  2. Jamie

    Jamie Well-Known Member

    Figured it out.. In case anyone else is wondering, here is an example I was playing around with to see if it worked.

    For Guest, the home tab is called Continue and for Members it's called Home.. I know, silly but it was a quick exercise to see how it worked. :)

    <xen:if is="{$visitor.user_id}">
    <li class="navTab home PopupClosed"><a href="{$homeLink}" class="navLink">{xen:phrase continue}</a></li>
    <xen:else />
    <li class="navTab home PopupClosed"><a href="{$homeLink}" class="navLink">{xen:phrase home}</a></li>
    </xen:if>
     
  3. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Based on that description I think you got the condition reversed. The first block is true for logged in users. The second block is true for guests.
     
  4. Jamie

    Jamie Well-Known Member

    Oh.. i thought this line: <xen:if is="{$visitor.user_id}"> was saying if this user IS a visitor... no?

    Jamie
    /learning curve here.. :)
     
  5. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Well, you are accessing the $visitor[] array, but you are specifically checking the user_id. Only logged in users have user_ids.

    The direct condition to check for guests is:

    Code:
    <xen:if is="!{$visitor.user_id}">
    	FOR GUESTS
    </xen:if>
    
    This reads, "if the user does not have a user_id."
     
    Jamie likes this.
  6. Jamie

    Jamie Well-Known Member

    Ah, ok. Thanks for your help! btw, how did you wrap that in the blue code tag? I looked but couldn't see a BBcode tag for that and ended up with smiles in my example. :)

    Jamie
     
  7. Jeremy P

    Jeremy P Well-Known Member

    That condition will determine if the person currently visiting the page has a user id, which only logged in users would.. so yes it is reversed.

    EDIT: Ahh too late.
     
  8. Jeremy P

    Jeremy P Well-Known Member

    You can use [code][/code] or [php][/php]
     
    Jamie likes this.
  9. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    [code]
    CODE STUFF HERE
    [/code]

    edit - Jeremy wins ;)
     
    Jamie likes this.
  10. yilmaz

    yilmaz Active Member

    I think so
    HTML:
    <xen:if is="{$visitor.user_id} == 0">
    For Guest
    <xen:else />
    For Members
    </xen:if>
     
    iMpAcK likes this.
  11. Lawrence

    Lawrence Well-Known Member

    It's quicker to just check the result of the condition:

    Code:
    <xen:if is="!{$visitor.user_id}">
    I'm a Guest visitor
    <xen:else />
    I'm a Member visitor
    </xen:if>
    
     
    iMpAcK and yilmaz like this.

Share This Page