Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Dec 2011
    Posts
    287
    Plugin Contributions
    0

    Default Active links based on current catagory

    Hi There!

    I have a header with some of my categories in a nav bar. The problem is that I would like the links to appear active based on the catagory that it is currently in. Take a look here:

    http://kitchenwarehouseltd.com/

    When in the kitchen doors category I would like the kitchen doors nav link have the active class. Is this possible?

  2. #2
    Join Date
    Jun 2005
    Location
    Cumbria, UK
    Posts
    10,267
    Plugin Contributions
    3

    Default Re: Active links based on current catagory

    Go get a copy of one of 12leaves "lite" templates. They have a header bar similar to yours that highlights the active link. Their template has a file called "top_nav.php" and the code that assist the process is as follows:

    PHP Code:
    <div id="top_nav">
    <div id="tab_nav">
    <!--<div class="top-nav-left"></div>-->
    <div class="top-nav-right"></div>
        <ul class="list-style-none">
            <li class="home-link"><a href="<?php echo '' HTTP_SERVER DIR_WS_CATALOG;?>"><!--img src="images/spacer.gif" width="1" height="14" alt=""--></a></li>

    <?php
    if ($current_page_base == 'products_new') {    $active    'tab_active'
        } else { 
    $active '';
    }
    ?>
            <li class="<?php echo $active;?>"><a href="index.php?main_page=products_new"><?php echo TOP_MENU_NEW_PRODUCTS;?></a></li>

    <?php
    if ($current_page_base == 'specials') { $active 'tab_active'
        } else { 
    $active '';
    }
    ?>
            <li class="<?php echo $active;?>"><a href="index.php?main_page=specials"><?php echo TOP_MENU_SPECIALS;?></a></li>

    <?php
    if ($current_page_base == 'account' || $current_page_base == 'login' || $current_page_base == 'account_edit' || $current_page_base == 'address_book' || $current_page_base == 'account_password' || $current_page_base == 'account_newsletters' || $current_page_base == 'account_notifications') { $active 'tab_active'
        } else { 
    $active '';
    }
    ?>
            <li class="<?php echo $active;?>"><a href="<?php echo zen_href_link(FILENAME_ACCOUNT'''SSL'); ?>"><?php echo TOP_MENU_MY_ACCOUNT;?></a></li>

    <?php
    if ($current_page_base == 'shopping_cart') { $active 'tab_active'
        } else { 
    $active '';
    }
    ?>
            <li class="<?php echo $active;?>"><a href="<?php echo zen_href_link(FILENAME_SHOPPING_CART'''NONSSL'); ?>"><?php echo TOP_MENU_VIEW_CART;?></a></li>
        </ul>
    </div>
    Of course, this must be manipulated in conjunction with appropriate CSS.
    20 years a Zencart User

  3. #3
    Join Date
    Dec 2011
    Posts
    287
    Plugin Contributions
    0

    Default Re: Active links based on current catagory

    This looks like a great start! The only problem I see is that I want the link to be active based on the current category not the current base page.

    I can imagine what I need would be the same as this but instead of
    Code:
    if ($current_page_base == 'products_new')
    It would be something like

    Code:
    if ($current_ category_id == '2')
    But im not sure what the correct code for this would be?

    Thanks for he help!

  4. #4
    Join Date
    Dec 2011
    Posts
    287
    Plugin Contributions
    0

    Default Re: Active links based on current catagory

    Oh I just tested and found my guess was correct! current_category_id is the correct code anyway.

    Thanks for the help!

    Danny

  5. #5
    Join Date
    Dec 2011
    Posts
    287
    Plugin Contributions
    0

    Default Re: Active links based on current catagory

    Sorry for the duplicate posts!

    I have run into a problem, current_category_id works great but then when I go deeper into the categories it seems to break as it doesn't include all subcategories.

    The only way I could think would be to actually type all the sub category id like:
    PHP Code:
    ($current_category_id == '2' || '3' || '4' || '5' || '6' || '7' || '35' || '120' || '155'
    The problem with this is that the category ids will change and update and it will be extremely hard to keep up with this. Can you guys think of any other way this could be done?

 

 

Similar Threads

  1. How to add active links in description?
    By dryaquaman in forum Setting Up Categories, Products, Attributes
    Replies: 4
    Last Post: 23 Apr 2011, 12:56 AM
  2. How to keep current tab/button active?
    By Berserker in forum General Questions
    Replies: 8
    Last Post: 29 Dec 2010, 07:57 AM
  3. No active links in IE !
    By alhakeem2001 in forum General Questions
    Replies: 3
    Last Post: 13 Dec 2009, 02:42 PM
  4. Replace catagories title with current catagory name.
    By chalfontgifts in forum General Questions
    Replies: 2
    Last Post: 7 Sep 2008, 07:52 AM
  5. Catagory based discounts
    By twrch2000 in forum Setting Up Categories, Products, Attributes
    Replies: 2
    Last Post: 26 Jul 2006, 02:24 PM

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