Is there an easier more efficient way to hide/show menu items to logged in, logged out users? It seems like I should not have to copy the whole menu again with duplicate menu items. The menu items maybe in different order like below
You can see in my example below I have added to links in the <?php } else { ?>
statement
<?php
if($_SESSION["loggedIn"] == "yes") {
?>
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="retailers.php">Stores</a></li>
<li><a href="coupons.php">Coupons</a></li>
<li><a href="featured.php">Featured Offers</a></li>
<li><a href="howitworks.php">How It Works</a></li>
<li><a href="help.php">Help</a></li>
</ul>
<?php } else { ?>
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="retailers.php">Stores</a></li>
<li><a href="coupons.php">Coupons</a></li>
<li><a href="myaccount.php">My Account</a></li>//logged in item
<li><a href="featured.php">Featured Offers</a></li>
<li><a href="howitworks.php">How It Works</a></li>
<li><a href="help.php">Help</a></li>
<li><a href="myfavorites.php">My Favorite Stores</a></li>//logged in item
</ul>
<?php
}
?>
Updated for new ordering of items:
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="retailers.php">Stores</a></li>
<li><a href="coupons.php">Coupons</a></li>
<?php
if($_SESSION["loggedIn"] == "yes") {
echo '<li><a href="myaccount.php">My Account</a></li>';
}
?><li><a href="featured.php">Featured Offers</a></li>
<li><a href="howitworks.php">How It Works</a></li>
<li><a href="help.php">Help</a></li>
<?php
if($_SESSION["loggedIn"] == "yes") {
echo '<li><a href="myfavorites.php">My Favorite Stores</a></li>';
}
?>
</ul>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With