New Zenner
- Join Date:
- Apr 2006
- Location:
- Columbus, OH
- Posts:
- 97
- Plugin Contributions:
- 0
is on-state look available for navigation?
Is there a way in zen-cart to set up an on-state look for the navigation?
Views: 1,152
New Zenner
Is there a way in zen-cart to set up an on-state look for the navigation?
Black Belt
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.
New Zenner
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?
Black Belt
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.
<?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 } ?>
```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).
New Zenner
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:
Black Belt
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 this```php
if($current_page_base == 'page' and $_GET['id'] == 2){
// <li> for Interview
New Zenner
That worked. Any idea how i can get this to work for categories? I have two categories, books and music, that have navigation items where I want to use the same effect. I tried using the ez-page code, but not sure what to replace "page" with (or whatever I need to change on that line).
Black Belt
Which navigation items do you want to affect? That is necessary to know before we can answer you.
Black Belt
Do you mean the same custom nav menus?
if($current_page_base == 'index' and $cPath == 2){
// <li> for Music
New Zenner
that sorta worked. One navigation item is going to a specific product in a category (cPath=1, ProductID=1). When you go to that product, the button isn't getting greyed out. Do I need to do something additonal to the code? I was hoping that just using the cPath would work. Here's the code below for that one and a link to the site:
<ul id="navigation"> <?php if($current_page_base == 'index' and $_GET['cPath'] == 1){ ?> <li id="nav_order" class="currentpage"><a href="http://www.thepresidentscroogereport.com/index.php?main_page=product_info&cPath=1&products_id=1"id="lastitem">Order</a></li> <?php }else{ ?> <li id="nav_order"><a href="http://www.thepresidentscroogereport.com/index.php?main_page=product_info&cPath=1&products_id=1"id="lastitem">Order</a></li> <?php } ?> </ul>site URL: http://www.thepresidentscroogereport.com
Black Belt
The specific product link would not use 'index' but 'product_info' page base, and $_GET['products_id'] == '1'.
href="http://www.thepresidentscroogereport.com/index.php?main_page=product_info&cPath=1&products_id=1"
New Zenner
that did it. Thanks a lot.
Tell staff why this post should be reviewed.