Post by dashik » Mon Nov 16, 2009 9:27 am

Is it possible to do this?

I have a secondary navigation menu with my categories...but I'd like to get each one to have an active background color once you're ON that category page.

I've done this many times but never in OC...really all I need is the ability to print the category_id on the main layout.tpl page so I can insert some css code into the <head> like this:

Code: Select all

<style type="text/css">
#cat<?php $category_id;?> a:link {
color: #fff;
}
#cat<?php $category_id;?> a:visited {
color: #fff;
}
#catbg<?php $category_id;?> {
background-color: #677B73;
color: #fff;
}
</style>
And then of course I would label my nav bar with the appropriate css IDs: (let's say this category_id was "2")

Code: Select all

<li id="cat2"><a href="http://www.domain.com/test" id="catbg2">Test Item</a></li>
Thoughts?

New member

Posts

Joined
Fri Jul 31, 2009 8:10 pm

Post by moggiex » Mon Nov 16, 2009 5:09 pm

dashik wrote:Is it possible to do this?

I have a secondary navigation menu with my categories...but I'd like to get each one to have an active background color once you're ON that category page.

I've done this many times but never in OC...really all I need is the ability to print the category_id on the main layout.tpl page so I can insert some css code into the <head> like this:

Code: Select all

<style type="text/css">
#cat<?php $category_id;?> a:link {
color: #fff;
}
#cat<?php $category_id;?> a:visited {
color: #fff;
}
#catbg<?php $category_id;?> {
background-color: #677B73;
color: #fff;
}
</style>
And then of course I would label my nav bar with the appropriate css IDs: (let's say this category_id was "2")

Code: Select all

<li id="cat2"><a href="http://www.domain.com/test" id="catbg2">Test Item</a></li>
Thoughts?
I need this is as well, I think I need to go back and look at that breadcrumb function I saw that is used in the header and instead of it being created, to spill it as an array, then we can pick off which cats we want!

Its a bit hacky atm, imho it would be better if there was a broader set of standard set of fields available for each page, thus a designers job would be miles easier as everything they should need to know about the category and product is already there.

Anyway, I'll take a look-see tonight.

Matt

Code: Select all

It was like that when I found it, honest!


User avatar
Active Member

Posts

Joined
Mon Nov 09, 2009 9:55 pm

Post by dashik » Tue Nov 17, 2009 12:17 pm

Matt, any luck?

New member

Posts

Joined
Fri Jul 31, 2009 8:10 pm

Post by dashik » Tue Nov 17, 2009 11:39 pm

I just realized the categories module does something similar (it bolds the current category whether you're on the category page or on that product's page).

In /catalog/controller/module/category.php -- inside the getCategories function is this:

Code: Select all

if ($this->category_id == $result['category_id']) {
				$output .= '<a href="' . $this->model_tool_seo_url->rewrite($this->url->http('product/category&path=' . $new_path))  . '"><b>' . $result['name'] . '</b></a>';
			} else {
				$output .= '<a href="' . $this->model_tool_seo_url->rewrite($this->url->http('product/category&path=' . $new_path))  . '">' . $result['name'] . '</a>';
			}
It's that first bit that adds the bold tags to the list item. Anyone know an easy way to replicate this on the main layout template?

New member

Posts

Joined
Fri Jul 31, 2009 8:10 pm
Who is online

Users browsing this forum: No registered users and 44 guests