Forum
Two sign out buttons?
Hi,
For some reason, I have two sign out buttons! This is in my Global Header template and the relevant code I am using is as follows. I have tried to use a php 'if' to display a 'Sign In' button whilst the user isn't signed in. And then display a 'Sign Out' button when the user is signed in.
<?php
$cart_count = perch_shop_cart_item_count([], true);
$cart_classes = 'cart';
if($cart_count > 0)
{
$cart_classes .= ' has-items';
}
if(perch_member_logged_in())
{
$account_link_name = 'Sign out';
}
else
{
$account_link_name = 'Sign in';
}
?>
<nav class="navbar is-transparent">
<div class="navbar-brand">
<a class="navbar-item" href="/">
<img src="/assets/img/Sandford-Parks-Lido-Cheltenham.png" alt="Sandford Parks Lido is one of the largest outdoor swimming pools in the UK, set in landscaped gardens in Cheltenham, England." width="130" height="51">
</a>
<div class="navbar-burger burger" data-target="navbarExampleTransparentExample">
<span></span>
<span></span>
<span></span>
</div>
</div>
<div id="navbarExampleTransparentExample" class="navbar-menu">
<div class="navbar-start">
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link" href="/">
Shop
</a>
<div class="navbar-dropdown is-boxed">
<a class="navbar-item" href="/photo-upload">
Upload photo
</a>
<a class="navbar-item" href="/shop/checkout-stage-one">
Required concession documentation
</a>
<a class="navbar-item" href="/concession-application">
Apply for concessions
</a>
</div>
</div>
<a class="navbar-item" href="https://www.sandfordparkslido.org.uk/">
Return to main site
</a>
</div>
<div class="navbar-end">
<div class="navbar-item">
<div class="field is-grouped">
<p class="control">
<a class="button is-primary" href="/checkout" >
<span class="icon is-small"><i class="fa fa-user-circle-o" aria-hidden="true"></i></span>
<span><?php echo $account_link_name; ?></span>
</a>
</p>
<?php if(perch_member_logged_in()): ?>
<p class="control">
<a class="button is-primary" href="/shop/logout">
<span class="icon is-small"><i class="fa fa-user-circle-o" aria-hidden="true"></i></span>
<span><?php echo $account_link_name; ?></span>
</a>
</p>
<?php endif; ?>
So the relevant bit of code that isn't producing the results I intended is:
<?php if(perch_member_logged_in()): ?>
Would appreciate a bit of help...
Hello Grant,
It seems you are echoing
$account_link_name
twice. Once before theif
statement and once inside it.Thank for this Hussein, although I do not disagree with your post, I am still struggling to get this work as expected?
Essentially the Sign in remains although the user is logged in.
Have you tried removing the one you don't want?
So here is what I have tried…
Result: Sign in and Sign out button once logged in
Result: Two Sign out buttons once logged in
Result: No Sign in button
Result: One button, but can not log out once logged in
What does this give you?
It gives me exactly what I am after!!!
Thanks very much, appreciate the help