Page 1 of 1

Changing stylesheet depending on category?

Posted: Tue Aug 31, 2010 7:03 pm
by 900pixels
Hi can someone let me know how it would be possible to change the stylesheet depending on the category chosen?

In my searches I found something which may be very similar code-wise in Q's post in this thread about loading a banner depending on the page.
http://forum.opencart.com/viewtopic.php ... 351#p60483

Thanks for any help you guys can offer!

Re: Changing stylesheet depending on category?

Posted: Tue Aug 31, 2010 9:57 pm
by 900pixels
An update-
I can get 2 different stylesheets loading for the home page and the contact us page using the code below

Code: Select all

<?php if (!isset($this->request->get['route']) || $this->request->get['route'] == 'common/home') { ?>
<link rel="stylesheet" type="text/css" href="catalog/view/theme/<?php echo $template; ?>/stylesheet/stylesheet2.css" />
<?php } ?>
<?php if (!isset($this->request->get['route']) || $this->request->get['route'] == 'information/contact') { ?>
<link rel="stylesheet" type="text/css" href="catalog/view/theme/<?php echo $template; ?>/stylesheet/stylesheet.css" />
<?php } ?>
but I get no stylesheet if I substitute the route for something from a category like this

Code: Select all

<?php if (!isset($this->request->get['route']) || $this->request->get['route'] == 'product/category&path=18) { ?>
<link rel="stylesheet" type="text/css" href="catalog/view/theme/<?php echo $template; ?>/stylesheet/stylesheet.css" />
<?php } ?>
Can anyone shed some light on why this is happening?
Would SEO URLs be better?

Re: Changing stylesheet depending on category?

Posted: Tue Aug 31, 2010 10:40 pm
by Qphoria

Code: Select all

<?php if (!isset($this->request->get['route']) || $this->request->get['route'] == 'product/category&path=18) { ?>
The route only consists of 'product/category'
You are adding the path as part of the route.. but the path is the path

Try this

Code: Select all

<?php if (!isset($this->request->get['path']) || $this->request->get['path'] == '18') { ?>

Re: Changing stylesheet depending on category?

Posted: Wed Sep 01, 2010 5:55 am
by 900pixels
Thankyou so much Q.
You are a legend!

Re: Changing stylesheet depending on category?

Posted: Sun Feb 13, 2011 5:50 pm
by webpie it.
referrring to the code that loads a different style-sheet depending on page, where abouts in header.tpl do you put this and what do you remove?

Thanks

Chris

Re: Changing stylesheet depending on category?

Posted: Wed Feb 16, 2011 6:45 am
by 900pixels
Just look in the header.tpl file for the stylesheet.css link and put it after that.

Re: Changing stylesheet depending on category?

Posted: Fri Feb 17, 2012 7:58 am
by taylordsmith
Thanks for the solution! However, I'm running into a few problems..

How do you apply the new stylesheet to all of the subcategories and products? I can attach it to the main category page, but that's it.

Also, it is applying the new stylesheet to my home page as well - the other categories still use the default stylesheet. I assume my problems are stemming from confusion over the path structure (ie. "18" in the example).

Thanks for everyone's help so far. Any advice would be very much appreciated!

-Taylor

Re: Changing stylesheet depending on category?

Posted: Fri Jun 09, 2017 9:08 pm
by Opencart_k
Can the same be applied in opencart Version 2.3.0.2 ? Because I want to have different stylesheet in categories and this would not work for it.