Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Category specific stylesheet


fresco

Recommended Posts

Hi,

 

I have givenup my attempts to find the answer - surprized that it was not asked before:

 

How can I call a spesific (different) stylesheet per category?

 

Like

 

Catalog Main - stylesheet.css

 

Category Gadgets - gadgets-stylesheet.ccs

 

Category Widjets - widjets-stylesheet.css

 

i am usually ok to adapting other contributions to do what i need, but it does not work this time...

It should not be too complicated - just put a conditional like

 

if $category['categories_name']=true

print <link rel="stylesheet" type="text/css" href="<?php echo $category['categories_name']?>_stylesheet.css">

else

<link rel="stylesheet" type="text/css" href="stylesheet.css">

 

so whenever the visitor is on category page there will be a specific to the parent category stylesheet

and when the visitor is on other pages he gets default stylesheet

 

PS. I have no idea in the proper writing (of the code) usually I modify it by the "method of scientific poking" so please understand...

Link to comment
Share on other sites

look at this code :

<?php

// to be tested !!!!
function BasePath($MonPath) {
$pos = strpos($MonPath,"_"); // we search : "_"
if ($pos== False) {
return $MonPath;
break; // no subpath, we stop here !
}
$Base =  substr($MonPath, 0, $pos); // beginning of the string to "_" - 1
return $Base;  
}

$LePath = "0"; // by default

// in case
if (isset($_GET['cPath'])) {
$LePath = $_GET['cPath'];
$LePath = BasePath($LePath);
}

$dossier_css = ''; // <= css files folder to be completed
$css_files = 'stylesheet_cat' . $LePath . '.css';
if (file_exists($dossier_css . $css_files ) == False) {
$css_files = 'stylesheet.css';
}
?>

 

Need testing but it must work ! :P

MS2 2.2 fr + Manufacturer copy (5 manufacturers - modified to make it works) + More pics 6 + FCK Editor + zones shipping (modified without weight) + My contribution : Shopping Cart Management for Unique Products

 

I apologize in advance for my poor English I'm French !

Link to comment
Share on other sites

look at this code :

<?php

// to be tested !!!!
function BasePath($MonPath) {
$pos = strpos($MonPath,"_"); // we search : "_"
if ($pos== False) {
return $MonPath;
break; // no subpath, we stop here !
}
$Base =  substr($MonPath, 0, $pos); // beginning of the string to "_" - 1
return $Base;  
}

$LePath = "0"; // by default

// in case
if (isset($_GET['cPath'])) {
$LePath = $_GET['cPath'];
$LePath = BasePath($LePath);
}

$dossier_css = ''; // <= css files folder to be completed
$css_files = 'stylesheet_cat' . $LePath . '.css';
if (file_exists($dossier_css . $css_files ) == False) {
$css_files = 'stylesheet.css';
}
?>

 

Need testing but it must work ! :P

 

 

Thanks! But where do I put this code? - index.php instead of <link ref.... ?

Link to comment
Share on other sites

in index.php

you replace

<link rel="stylesheet" type="text/css" href="stylesheet.css">

by my code.

 

Good luck

MS2 2.2 fr + Manufacturer copy (5 manufacturers - modified to make it works) + More pics 6 + FCK Editor + zones shipping (modified without weight) + My contribution : Shopping Cart Management for Unique Products

 

I apologize in advance for my poor English I'm French !

Link to comment
Share on other sites

in index.php

you replace

<link rel="stylesheet" type="text/css" href="stylesheet.css">

by my code.

 

Good luck

 

 

do i create stylesheets named as stylesheet_cat1.css stylesheet_cat2.css stylesheet_cat2-3.css ?

if that is so is it possible to create "wildcard" for subcategories aka any cat2-x gets stylesheet for top-level cat 2

 

btw. I will be using your contr for unique items (building a jewelry store)

Link to comment
Share on other sites

well I made it to work, somehow... but not very efficiently

 

i was using friendly URLs that came with osC package - had to turn that off.

 

created file "styles" and put stylesheet_cat0.css (default stylesheet.css - it will not find the main one... when go to catalog index) and corresponding stylesheet_cat1.css , etc.

 

edited out some lines in your code and added <link rel="stylesheet" type="text/css" href="<?php echo $css_files; ?>">

 

<!-- styles start here //-->
<?php

// to be tested !!!!
function BasePath($MonPath) {
$pos = strpos($MonPath,"_"); // we search : "_"
if ($pos== False) {
return $MonPath;
break; // no subpath, we stop here !
}
$Base = substr($MonPath, 0, $pos); // beginning of the string to "_" - 1
return $Base;
}

$LePath = "0"; // by default

// in case
if (isset($_GET['cPath'])) {
$LePath = $_GET['cPath'];
$LePath = BasePath($LePath);
}

$dossier_css = 'styles'; // <= css files folder to be completed
$css_files = 'styles/stylesheet_cat' . $LePath . '.css';
//if (file_exists($dossier_css . '/' . $css_files ) == False) {
//$css_files = 'stylesheet.css';
//}
?>

<link rel="stylesheet" type="text/css" href="<?php echo $css_files; ?>">
<!-- styles end here //-->

 

 

I wonder if you can review my "scientific poking" edits and make them more "real"?

 

also is there any way to look for cpath elsewhere so modrewrites will work?

Link to comment
Share on other sites

we can do better than that, there is a function in application_top.php that give us the current categorie:

if (tep_not_null($cPath)) {
  $cPath_array = tep_parse_category_path($cPath);
  $cPath = implode('_', $cPath_array);
  $current_category_id = $cPath_array[(sizeof($cPath_array)-1)];
} else {
  $current_category_id = 0;
}

 

let's use it it's easier :

if (isset($current_category_id)) {
$css_folder = 'styles';
$css_files = 'stylesheet_cat'. $current_category_id . '.css';

if (file_exists($css_folder . $css_files ) == True) {
echo '<link rel="stylesheet" type="text/css" href="'. $css_folder . $css_files .' ">';
} else {
echo '<link rel="stylesheet" type="text/css" href="'. $css_folder . 'stylesheet.css">';
}
}

 

in that case we don't have to put "else" for each new css.

You just have to put the css for the category and it will be taken into account if the file exists.

On my side it works well except that $current_category_id gives us the child category but not the parent category ie for category 2_5 it takes the template 5 instead of 2 !

 

If I have time I will go deeper in the code :thumbsup:

MS2 2.2 fr + Manufacturer copy (5 manufacturers - modified to make it works) + More pics 6 + FCK Editor + zones shipping (modified without weight) + My contribution : Shopping Cart Management for Unique Products

 

I apologize in advance for my poor English I'm French !

Link to comment
Share on other sites

in that case we don't have to put "else" for each new css.

You just have to put the css for the category and it will be taken into account if the file exists.

On my side it works well except that $current_category_id gives us the child category but not the parent category ie for category 2_5 it takes the template 5 instead of 2 !

 

If I have time I will go deeper in the code :thumbsup:

 

well in your original code it would properly select the parent only, perhaps if you add that statement (strip _x) it would be just perfect.

 

and if you have time :ph34r: it would be somehow possible to keep the last category stylesheet into checkout... :-"

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...