Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Active links based on current catagory

Active links based on current catagory

Views: 489

Results 1 to 5 of 5
28 Feb 2013, 11:07 AM
#1
dannyvarley avatar

dannyvarley

Zen Follower

Join Date:
Dec 2011
Posts:
287
Plugin Contributions:
0

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?

28 Feb 2013, 12:23 PM
#2
schoolboy avatar

schoolboy

Totally Zenned

Join Date:
Jun 2005
Location:
Cumbria, UK
Posts:
10,327
Plugin Contributions:
0

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:

<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.

28 Feb 2013, 12:35 PM
#3
dannyvarley avatar

dannyvarley

Zen Follower

Join Date:
Dec 2011
Posts:
287
Plugin Contributions:
0

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

if ($current_page_base == 'products_new')

It would be something like

if ($current_ category_id == '2')

But im not sure what the correct code for this would be?

Thanks for he help!

28 Feb 2013, 12:40 PM
#4
dannyvarley avatar

dannyvarley

Zen Follower

Join Date:
Dec 2011
Posts:
287
Plugin Contributions:
0

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

28 Feb 2013, 1:11 PM
#5
dannyvarley avatar

dannyvarley

Zen Follower

Join Date:
Dec 2011
Posts:
287
Plugin Contributions:
0

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:

($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?