Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2010
    Posts
    133
    Plugin Contributions
    0

    Default Using php to switch menu items

    I want the menu shown to depend on whether a user is logged on or not:

    If not logged in, show:

    Login
    Register


    If logged in, show:

    Logout
    Member Services



    The following code shows all 4 selections:

    Code:
    <?php
    	$show_orcatools_sidebox = true;
    	if ($show_orcatools_sidebox == true){
    		require($template->get_template_dir('tpl_orcatools_sidebox.php',DIR_WS_TEMPLATE,
    		$current_page_base,'sideboxes'). '/tpl_orcatools_sidebox.php');
    		?>
    		<div id='leftfld'>
    			<div id="NavigationPanel">
    				<dl>
    					<dd class="nav1"><a class="nav1" href="index.php?main_page=login">Login</a></dd>
    					<dd class="nav1"><a class="nav1" href="index.php?main_page=Register">Register</a></dd>
    					<dd class="nav1"><a class="nav1" href="index.php?main_page=logoff">Logout</a></dd>
    					<dd class="nav1"><a class="nav1" href="index.php?main_page=Member Services">Membership</a></dd>
    				</dl>
    			</div>
    		</div>
    		<?php
    	}
    ?>
    I tried modifying it, but it still shows all 4 selections.

    Code:
    <?php
    	$show_orcatools_sidebox = true;
    	if ($show_orcatools_sidebox == true){
    		require($template->get_template_dir('tpl_orcatools_sidebox.php',DIR_WS_TEMPLATE,
    		$current_page_base,'sideboxes'). '/tpl_orcatools_sidebox.php');
    		?>	
    		<div id='leftfld'>
    			<div id="NavigationPanel">
    				<dl>
    					<?php
    					if ($_SESSION['customer_first_name'] == '') {
    					?>
    						<dd class="nav1"><a class="nav1" href="index.php?main_page=login">Login</a></dd>
    						<dd class="nav1"><a class="nav1" href="index.php?main_page=Register">Register</a></dd>
    					<?php
    					else
    					?>
    						<dd class="nav1"><a class="nav1" href="index.php?main_page=logoff">Logout</a></dd>
    						<dd class="nav1"><a class="nav1" href="index.php?main_page=Member Services">Membership</a></dd>
    					<?php
    					}
    					?>
    				</dl>
    			</div>
    		</div>
    		<?php
    	}
    ?>
    What am I missing here?

  2. #2
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Using php to switch menu items

    Use the navMain code from the original tpl_header.php that comes with Zen Cart. That checks
    PHP Code:
    if ($_SESSION['customer_id']){ 
    - if it is non-null, the customer is logged in.

  3. #3
    Join Date
    Jan 2010
    Posts
    133
    Plugin Contributions
    0

    Default Re: Using php to switch menu items

    Quote Originally Posted by gjh42 View Post
    Use the navMain code from the original tpl_header.php that comes with Zen Cart. That checks
    PHP Code:
    if ($_SESSION['customer_id']){ 
    - if it is non-null, the customer is logged in.
    OK, that gives me:

    Code:
    <?php if ($_SESSION['customer_id']){ ?>
    		<dd class="nav1"><a class="nav1" href="index.php?main_page=login">Login</a></dd>
    		<dd class="nav1"><a class="nav1" href="index.php?main_page=Register">Register</a></dd>
    <?php } else { ?>
    		<dd class="nav1"><a class="nav1" href="index.php?main_page=logoff">Logout</a></dd>
    		<dd class="nav1"><a class="nav1" href="index.php?main_page=Member Services">Membership</a></dd>
    <?php } ?>
    cleaner looking, but I still get all 4 selections.

  4. #4
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Using php to switch menu items

    Quote Originally Posted by OrcaSoul View Post
    ... but I still get all 4 selections.
    If it's giving you all FOUR selections, then they're NOT coming from THAT code.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  5. #5
    Join Date
    Jan 2010
    Posts
    133
    Plugin Contributions
    0

    Default Re: Using php to switch menu items

    Quote Originally Posted by DrByte View Post
    If it's giving you all FOUR selections, then they're NOT coming from THAT code.
    OK, somehow I had an extra page that was taking priority...

    That works,

    Thanks!

 

 

Similar Threads

  1. v154 removing menu items from header menu
    By Awalji in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 9 Jun 2015, 08:00 PM
  2. How to add menu items for top horizontal menu? - help
    By AndriyZ in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 7 Feb 2010, 01:14 AM
  3. Admin menu items/pages not using https/ssl
    By thuffam in forum General Questions
    Replies: 1
    Last Post: 26 May 2009, 11:42 AM
  4. Replies: 26
    Last Post: 4 Oct 2008, 06:09 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR