Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Per page stylesheets

Per page stylesheets

Locked

Views: 4,720

Results 1 to 12 of 12
This thread is locked. New replies are disabled.
14 Mar 2007, 18:01
#1
cshart avatar

cshart

Zen Follower

Join Date:
Mar 2005
Posts:
370
Plugin Contributions:
0

Per page stylesheets

I found a section in the wiki that said if you use index_home.css for the home page you can change the look of the home page and you should use the page name for all the other pages.

FIguring out what the page name might be is confusing since I would never have thought index_home.css was right for the home page.

So I need a little help with the naming of the new style sheets. I want to rename the style sheets for the ezpage pages so they look like the homepage and have the shopping cart part with another stylesheet. Plan to use the default stylesheet for the cart.

How do I figure out the page names for example cart/index.php?main_page=page&id=1&chapter=1

What do I put for this stylesheet or is there one for the ezpages all of them or can there be one for all the ezpages and how would I do that???

Thanks,

C

14 Mar 2007, 18:15
#2
clydejones avatar

clydejones

Deceased

Join Date:
Nov 2005
Location:
Colorado Springs, CO USA
Posts:
7,017
Plugin Contributions:
12

Re: Per page stylesheets

The first thing you'll need to do is open
includes/templates/template_default/common/html_header.php

Find the following code and add the portions highlighted in red

/**
 * 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;
  $sheets_array = array('/' . $_SESSION['language'] . '_stylesheet', 
                        '/' . $tmp_pagename, 
                        '/' . $_SESSION['language'] . '_' . $tmp_pagename, 
                        '/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
                         '/chapter_' . $chapter_id,
                        '/' . $_SESSION['language'] . '_chapter_' . $chapter_id,
                        '/ezpage_' . $ezpage_id,
                        '/' . $_SESSION['language'] . '_ezpage_' . $ezpage_id  
                        );

Save the file to includes/templates/YOUR_TEMPLATE/common/html_header.php

and upload to your server.

Now you can name your stylesheets as follows:

chapter_1.css or ezpage_2.css

15 Mar 2007, 14:21
#3
cshart avatar

cshart

Zen Follower

Join Date:
Mar 2005
Posts:
370
Plugin Contributions:
0

Re: Per page stylesheets

Thanks it worked. I changed all the chapter numbers on my ezpages to 0 and thus only needed one new stylesheet. I did not want to use the TOC.

C

22 Apr 2008, 22:28
#4
rmullaney77 avatar

rmullaney77

New Zenner

Join Date:
Mar 2007
Location:
Lakeland, FL, US
Posts:
44
Plugin Contributions:
1

Re: Per page stylesheets

Great addition that should be considered as a core update IMO.

For anyone using this code modification, don't forget to include a comma after $tmp_products_id

18 May 2008, 17:45
#5
newy_newbie avatar

newy_newbie

New Zenner

Join Date:
May 2008
Posts:
7
Plugin Contributions:
0

Re: Per page stylesheets

Hi. I was wondering what the code would be for using this technique to create stylesheets for individual categories in html_header.php?

Also I notice an option at the top of each page on the forums to sign up for the newsletter using only your email address. I want to add this option to my site but am unsure how to do it. I've downloaded the newsletter_only subscriptions module but am not sure if it does what I want or how to get it to work like I want. It says there should be a sidebox for it in 'Layout Boxes Controller' in the admin backend but I can't find. Any help appreciated. Thanks.

18 May 2008, 18:01
#6
fairestcape avatar

fairestcape

Totally Zenned

Join Date:
Mar 2008
Location:
Cape Town & London (depends on the season)
Posts:
2,957
Plugin Contributions:
0

Re: Per page stylesheets

newy_newbie:

Hi. I was wondering what the code would be for using this technique to create stylesheets for individual categories in html_header.php?

The function for categories is already there...

                    '/c_' . $cPath,
                    '/' . $_SESSION['language'] . '_c_' . $cPath,

There's a "read-me" in the CSS folder, explaining the procedure.

18 May 2008, 18:09
#7
newy_newbie avatar

newy_newbie

New Zenner

Join Date:
May 2008
Posts:
7
Plugin Contributions:
0

Re: Per page stylesheets

Thanks. I've taken a look at that and while it's clearly the solution I need I'm afraid I still don't fully understand. Basically I want to put all the products in some categories in catalog-mode and the products in some other categories in shopping cart mode. I believe I can achieve this by stipulating 'display:none;' for the 'Add To Cart' button in the product description for the products in certain categories but I'm unsure what the naming convention is for that or how to target specific pages in the stylessheets or even what to name the stylesheets to target these pages/categories. I know that the answer is probably simple and I'm almost there but any help would be greatly appreciated. Thank you.

18 May 2008, 18:24
#8
newy_newbie avatar

newy_newbie

New Zenner

Join Date:
May 2008
Posts:
7
Plugin Contributions:
0

Re: Per page stylesheets

Perhaps I should be a bit clearer. I want to take out the Add to Cart button in the product description of an item under the category 'Books'. According to the web developer add-on the id I want to target is '#cartAdd'. And according to the read-me file in the css directory I should create a file called 'c_??_??.css' and upload it to the 'classic>css' override directory. According to the read-me file this makes "changes to all info pages in a category".

So I should name this file c_books.css, include '#cartAdd { display:none; }' in it and upload it and this should do what I want, take out the Add to Cart function in that product description in that category only. Thing is, I've done that but it doesn't work. Obviously I'm doing something wrong but I don't know what. Any ideas?

19 May 2008, 09:03
#9
fairestcape avatar

fairestcape

Totally Zenned

Join Date:
Mar 2008
Location:
Cape Town & London (depends on the season)
Posts:
2,957
Plugin Contributions:
0

Re: Per page stylesheets

You don't work with category NAMES in naming the css file:-

c_??_??.css

...where ??_?? are the category ID numbers.

There are a few places where you can see these ID numbers - in ADMIN>>>CATALOG>>>CATEGORIES/PRODUCTS

When your table of categories displays, you can see the ID number in the left column.

Additionally, if you call up a product in any category, look at your browser address bar:-

index.php?main_page=product_info&cPath=24_31&products_id=300

This line says:-

Display the main page for the main category ID=24 and it's sub category ID=31, (and then show product with Product ID=300.)

So, if I wanted to create a unique stylesheet for that sub-category, my CSS file would be called:-

c_24_31.css

(NOTE: If you don't use sub-categories, then you will only have ONE ID number for a category)

(If I wanted to create a product-specific stylesheet for the product in that URL, I would create a stylesheet p_300.css).

12 Jun 2008, 19:42
#10
jaydee98273 avatar

jaydee98273

New Zenner

Join Date:
May 2008
Posts:
28
Plugin Contributions:
0

Re: Per page stylesheets

This technique works great. One question though. Is it possible to have a custom style sheet that applies to all categories? If so, what would I name it?

12 Jun 2008, 20:14
#11
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Per page stylesheets

You wouldn't be using a per-category stylesheet for that, it would be a per-page stylesheet like product_info.css.

16 Nov 2010, 02:42
#12
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Per page stylesheets

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.