Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Different stylesheet for different categories


toyicebear

Recommended Posts

Posted

Hei....

 

 

I am currently working on a project which requires the color scheme to change according to category. Since i am no php wiz... , i am hoping there is someone out there who can point me in the right direction.....

 

For instance would a simple if, else statement related to category id work? or would it require making a separat function which is called according to category?

 

Any input is appriciated.....

Posted
For instance would a simple if, else statement related to category id work?

I guess that could work, if you load a different stylesheet.css for that category or overrule the css stylesheet with <style> </style> in the head section.

 

Depending on the category id you could do an include of a file from (e.g.) a separate subdirectory in (e.g.) includes. This would be triggered by the $_GET['cPath'] variable.

 

If it is set and there is an include for that category (which you could name style_1_2.inc.php for the style sheet for category 1_2 for example) it includes that file (which would start with <style> .subHeading { styles that are different } </style> ) and if it not there wouldn't be included anything.

 

Just what I would try, but there might be much easier solutions where I haven't thought of....

  • 2 weeks later...
Posted

I have done this in my project as the requirement were for the product heading text to be different colours according to categories as well as the table backgrounds. I will include a segment of code below.

Near the top of catalog/product_info.php I have this segment of code;

	switch ($cPath){
  case 21:
	 $myClass = "Steel";
	 break;
 case 22:
   $myClass = "Brass";
	 break;
 case 23:
   $myClass = "Stainless";
	 break;
 case 24:
   $myClass = "Silicon";
	 break;
  default:
   $myClass = "";
 }

 

Note: if you don't use master products, this could be inserted into catalog/includes/modules/product_listing.php.

I use master products contribution so in my catalog/includes/modules/master_listing.php I have the code below starting at line 114. Note the use of the $myClass variable;

     if ( ($column_list[$col] != 'MASTER_LIST_BUY_NOW') && ($column_list[$col] != 'MASTER_LIST_IMAGE' && ($column_list[$col] != 'MASTER_LIST_MULTIPLE' && ($column_list[$col] != 'MASTER_LIST_DESCRIPTION'))) ) {
     $lc_text = tep_create_sort_heading($HTTP_GET_VARS['sort'], $col+1, $lc_text);
   }

   $list_box_contents[0][] = array('align' => $lc_align,
                                   'params' => 'class="productListing'.$myClass.'-heading"',
                                   'text' => $lc_text);
 }

 if ($listing_split->number_of_rows > 0) {
   $rows = 0;
   $master_query = tep_db_query($listing_split->sql_query);
   while ($listing = tep_db_fetch_array($master_query)) {
     $rows++;

     if (($rows/2) == floor($rows/2)) {
       $list_box_contents[] = array('params' => 'class="productListing'.$myClass.'-even"');
     } else {
       $list_box_contents[] = array('params' => 'class="productListing'.$myClass.'-odd"');
     }

 

Then in stylesheet.css, I have duplicated the productListing-heading, productListing-odd and productListing-even classes for each category as shown below with the 'steel' example;

TD.pageHeadingSteel {
 font-family: Verdana, Arial, sans-serif;
 font-size: 20px;
 font-weight: bold;
 color: #006632;
}

.productListingSteel-heading {
 font-family: Verdana, Arial, sans-serif;
 font-size: 10px;
 background: #efefe7;
 color: #006632;
 font-weight: bold;
}

TR.productListingSteel-odd {
background: #efefe7;
}

TR.productListingSteel-even {
 background: #efefe7;
}

 

While I would like to post the URL to show you the working sample, it is a dealer only site and therefore not appropriate for general publication.

Kerry Slavin
  • 2 years later...
Posted

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...