People have asked about having a per-category stylesheet which applies to all subcats of a top cat.
I know this feature has been described elsewhere, but I did not find it readily, so am posting a version here which includes clydejones' code in a search-efficient manner.
This is based on the v1.3.9 version of /includes/templates/template_default/common/html_header.php.
Change this line (about line 58)```php
if ($current_page_base == 'page' && isset($ezpage_id)) $tmp_pagename = $current_page_base . (int)$ezpage_id;
to this:```php
//if ($current_page_base == 'page' && isset($ezpage_id)) $tmp_pagename = $current_page_base . (int)$ezpage_id; //only allows per-ezpage stylesheets, not generic page
if ($current_page_base == 'page' && isset($ezpage_id)) {
if (isset($chapter_id)) {
$chapter_sheet = '/chapter_' . $chapter_id;
$chapter_lan_sheet = '/' . $_SESSION['language'] . '_chapter_' . $chapter_id;
}
$ezpage_sheet = '/ezpage_' . $ezpage_id;
$ezpage_lan_sheet = '/' . $_SESSION['language'] . '_ezpage_' . $ezpage_id;
}
$top_cat_sheet = (substr_count($cPath,'_')) ? '/c_' . (int)$cPath : '';
$top_cat_lan_sheet = (substr_count($cPath,'_')) ? '/' . $_SESSION['language'] . '_c_' . (int)$cPath : '';
Add after this line ```php
'/' . $SESSION['language'] . '' . $tmp_pagename,
to get this:```php
'/' . $_SESSION['language'] . '_' . $tmp_pagename,
$chapter_sheet,
$chapter_lan_sheet,
$ezpage_sheet,
$ezpage_lan_sheet,
$top_cat_sheet,
$top_cat_lan_sheet,
And alter the while() section```php
while(list ($key, $value) = each($sheets_array)) {
//echo "<!--looking for: $value-->\n";
$perpagefile = $template->get_template_dir('.css', DIR_WS_TEMPLATE, $current_page_base, 'css') . $value . '.css';
if (file_exists($perpagefile)) echo '<link rel="stylesheet" type="text/css" href="' . $perpagefile .'" />'."\n";
}
to get this:```php
while(list ($key, $value) = each($sheets_array)) {
if ($value) { //filter blank values
//echo "<!--looking for: $value-->\n";
$perpagefile = $template->get_template_dir('.css', DIR_WS_TEMPLATE, $current_page_base, 'css') . $value . '.css';
if (file_exists($perpagefile)) echo '<link rel="stylesheet" type="text/css" href="' . $perpagefile .'" />'."\n";
}
}
The complete stylesheet loading code section, expanding on clydejones' example, will then look like this:
/**
* load stylesheets on a per-page/per-language/per-product/per-manufacturer/per-category basis. Concept by Juxi Zoza.
*/
$manufacturers_id = (isset($_GET['manufacturers_id'])) ? $_GET['manufacturers_id'] : '';
$tmp_products_id = (isset($_GET['products_id'])) ? (int)$_GET['products_id'] : '';
$tmp_pagename = ($this_is_home_page) ? 'index_home' : $current_page_base;
//if ($current_page_base == 'page' && isset($ezpage_id)) $tmp_pagename = $current_page_base . (int)$ezpage_id; //only allows per-ezpage stylesheets, not generic page
if ($current_page_base == 'page' && isset($ezpage_id)) {
if (isset($chapter_id)) {
$chapter_sheet = '/chapter_' . $chapter_id;
$chapter_lan_sheet = '/' . $_SESSION['language'] . '_chapter_' . $chapter_id;
}
$ezpage_sheet = '/ezpage_' . $ezpage_id;
$ezpage_lan_sheet = '/' . $_SESSION['language'] . '_ezpage_' . $ezpage_id;
}
$top_cat_sheet = (substr_count($cPath,'_')) ? '/c_' . (int)$cPath : '';
$top_cat_lan_sheet = (substr_count($cPath,'_')) ? '/' . $_SESSION['language'] . '_c_' . (int)$cPath : '';
$sheets_array = array('/' . $_SESSION['language'] . '_stylesheet',
'/' . $tmp_pagename,
'/' . $_SESSION['language'] . '_' . $tmp_pagename,
$chapter_sheet,
$chapter_lan_sheet,
$ezpage_sheet,
$ezpage_lan_sheet,
$top_cat_sheet,
$top_cat_lan_sheet,
'/c_' . $cPath,
'/' . $_SESSION['language'] . '_c_' . $cPath,
'/m_' . $manufacturers_id,
'/' . $_SESSION['language'] . '_m_' . (int)$manufacturers_id,
'/p_' . $tmp_products_id,
'/' . $_SESSION['language'] . '_p_' . $tmp_products_id
);
while(list ($key, $value) = each($sheets_array)) {
if ($value) { //filter blank values
//echo "<!--looking for: $value-->\n";
$perpagefile = $template->get_template_dir('.css', DIR_WS_TEMPLATE, $current_page_base, 'css') . $value . '.css';
if (file_exists($perpagefile)) echo '<link rel="stylesheet" type="text/css" href="' . $perpagefile .'" />'."\n";
}
}
Save the file to includes/templates/YOUR_TEMPLATE/common/html_header.php
and upload to your server.