Page 1 of 1

Check if current is a product page

Posted: Thu Jul 29, 2010 1:07 pm
by idiotao
I've been developing a template for my new store and came across one problem. The main navigation on the store is customized and coded into the template (header.tpl) directly, and each link changes background on mouse hover.

Now I would like the link to the "Products" be highlighted when a user is on a product item page or product category page. I've prepared a CSS class for it, but I have no idea how to check whether the current page is a product item/category page or not.

Please help.
Big thanks.

Re: Check if current is a product page

Posted: Thu Jul 29, 2010 5:35 pm
by idiotao
Never mind that. I've found a solution by using

Code: Select all

$this->request->get['route']

Re: Check if current is a product page

Posted: Fri Jul 30, 2010 4:07 am
by deuce
For those of you without much PHP knowledge, I took this concept and added something like this to my header.tpl in the theme file.

Code: Select all

<?php 
	$page_route = explode('/',$this->request->get['route']);
	$body_class = '';
	foreach($page_route as $route){
		$body_class .= $route.' ';
	}
	$body_class = substr($body_class,0,-1);
?>

<body class="<?php echo $body_class; ?>">
This will give you something like

Code: Select all

<body class="product category">

when you're on the category page.

Re: Check if current is a product page

Posted: Fri Jul 30, 2010 6:50 pm
by dramony
Do you have a demo for this?
Thanks!