Is there a way in zen-cart to set up an on-state look for the navigation?
Is there a way in zen-cart to set up an on-state look for the navigation?
Not built in, but anything can be coded. A test for $current_page_base == 'whatever' would give you the basis for setting a "currentPage" class, which could be styled in the stylesheet.
The categories sidebox already has the classes for this available and ready to be styled. The Classic template uses these classes.
I'm a real novice at PHP. So say I wanted to apply an additional class to a navigation list item using this method, how would I alter the code? Currently, I have the navigation in its own component (navigation.php) and inserting in on the main page template. Here's the basic structure for the nav items:
<ul id="mainnav">
<li id="nav_home"><a href="[link to home page]">Home</a></li>
[other nav list here]
</ul>
I'm thinking the best way is to use the $current_page_base to add a class to the list item so that it looks like this:
<li id="nav_home" class="currentpage"><a href="[link to home page]">Home</a></li>
PHP-wise, how would I code that?
If you're going to add code to highlight the current page link, you might as well make it not a link to itself at the same time. It's a good practice to avoid links that lead to exactly where you are - they serve no purpose.
There are various other things you can test for different situations, like $_SESSION['customer_id'] to tell if the customer is logged in (so you can show the login or logout link as appropriate).PHP Code:<?php if($this_is_home_page){ ?>
<li id="nav_home" class="currentpage">Home</li>
<?php }else{ ?>
<li id="nav_home" class="notcurrentpage"><a href="[link to home page]">Home</a></li>
<?php } ?>
<?php if($current_page_base == 'contact_us'){ ?>
<li id="nav_contact" class="currentpage">Contact Us</li>
<?php }else{ ?>
<li id="nav_contact" class="notcurrentpage"><a href="[link to contact page]">Contact Us</a></li>
<?php } ?>
thanks. If I go that route (which seems like the best), how do I modify the links that go to ez-pages as well as product category pages? Here's the actual site to give you an idea what I mean:
http://www.thepresidentscroogereport.com/
Looks like fun!
It would have been simpler to use the existing ez-page sidebox and footer menus, with ez-page internal links to lead to other pages, but now that you have it, you may as well keep it.
Ez-page detection can be done like thisPHP Code:if($current_page_base == 'page' and $_GET['id'] == 2){
// <li> for Interview