Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Coding css changes into 2 category 3 subcategory tpl_categories.php

Coding css changes into 2 category 3 subcategory tpl_categories.php

Locked

Views: 8,248

Results 1 to 14 of 14
This thread is locked. New replies are disabled.
19 Jul 2007, 11:52 AM
#1
dvasdekis avatar

dvasdekis

New Zenner

Join Date:
Nov 2006
Posts:
70
Plugin Contributions:
0

Coding css changes into 2 category 3 subcategory tpl_categories.php

As seen in THIS thread, I've managed to get quite a nifty 2 category 3 subcategory sidebox going, thanks to the marvellous gjh (who I hope works for the zen team, because that's where the donation is going! :D). All the information about that work can be found in THIS thread. For perusal, the site in its current form is HERE.

I essentially need to do two things. Firstly, I need to implement some CSS styling to turn my current Categories - Tabs menu from THIS (links to the site, a standard setup categories-tabs header) currently, into THIS. I've been told that I can accomplish this using CSS alone, but I'm at a loss on how to achieve it. I know a small amount of CSS but not enough to get the job done. I would, of course, love to learn. I've experimented but to no avail on this topic.

As an aside that really isn't relevant for it to work, but hopefully as a piece of information that someone finds and puts to good use, the way I want the category-tabs header would work for these two categories, Headphones and Microphones, would be for the category to be a dark shade with the pink brackets next to it when the category is selected, and for the other category to be a lighter colour (I'm hoping to do all this through images in the current font). Then, when you hover over the other category, it turns dark as well. A consequence of this would be that troublesome flicker you see when you hover over most images on the Internet, but I found a neat trick to make the hover image pre-load in CSS:

a { background: url(image_hover.gif); }
a:link { background: url(image_default.gif); }
a:hover,
a:focus { background: url(image_hover.gif); }

The second aspect of the site that I'd like to get working is the main subcategory part. Basically what we managed to achieve in the last thread is to get some div tables happening. The relevant bit of PHP code in my tpl_categories.php is here:

  $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">' . "\n";
  $content .= '<div id="catPrice">';//bof price box
  for ($i=0;$i<sizeof($box_categories_array);$i++) {
    switch(true) {  
// to make a specific category stand out define a new class in the stylesheet example: A.category-holiday
// uncomment the select below and set the cPath=3 to the cPath= your_categories_id
// many variations of this can be done
//      case ($box_categories_array[$i]['path'] == 'cPath=3'):
//        $new_style = 'category-holiday';
//        break;
      case ($box_categories_array[$i]['top'] == 'true'):
        $new_style = 'category-top';
        break;
      case ($box_categories_array[$i]['has_sub_cat']):
        $new_style = 'category-subs';
        break;
      default:
        $new_style = 'category-products';
    }
    $current_path = str_replace("cPath=","",$box_categories_array[$i]['path']);
    if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1)) {
      // skip if this is for the document box (==3) 
    } else {
      // categories dressing - add divider above specified cats
      if(in_array($current_path, explode(",",'3,22,21_56'))) { //replace numbers with your cat ids separated by commas
        $content .= '<hr class="catBoxDivider" />' . "\n";
      }
      // categories dressing - add (divider and) heading above a cat
      $disp_block_head = '';
      //$disp_block_head = '<br />';  // for heading not block uncomment this line
      switch ($current_path) {
      case ('1_12'): //replace numbers with your desired cPaths
        $content .= '</div><div id="catType" />' . "\n";
        $content .= '<span class="catBoxHeading1">' . (file_exists(DIR_WS_TEMPLATE_IMAGES . 'cathead' . $current_path . '.gif') ? zen_image(DIR_WS_TEMPLATE_IMAGES . 'cathead' . $current_path . '.gif') . '</span>':'Heading 1</span>' . $disp_block_head) . "\n"; 
      break;
      case ('2_30'): //replace numbers with your desired cPaths
        $content .= '</div><div id="catMType" />' . "\n";
        $content .= '<span class="catBoxHeading1">' . (file_exists(DIR_WS_TEMPLATE_IMAGES . 'cathead' . $current_path . '.gif') ? zen_image(DIR_WS_TEMPLATE_IMAGES . 'cathead' . $current_path . '.gif') . '</span>':'Heading 1</span>' . $disp_block_head) . "\n"; 
      break;
          case ('1_16'): //replace numbers with your desired cPaths
        $content .= '</div><div id="catBrand" />' . "\n";
        $content .= '<span class="catBoxHeading1">' . (file_exists(DIR_WS_TEMPLATE_IMAGES . 'cathead' . $current_path . '.gif') ? zen_image(DIR_WS_TEMPLATE_IMAGES . 'cathead' . $current_path . '.gif') . '</span>':'Heading 1</span>' . $disp_block_head) . "\n"; 
      break;
          case ('2_34'): //replace numbers with your desired cPaths
        $content .= '</div><div id="catMBrand" />' . "\n";
        $content .= '<span class="catBoxHeading1">' . (file_exists(DIR_WS_TEMPLATE_IMAGES . 'cathead' . $current_path . '.gif') ? zen_image(DIR_WS_TEMPLATE_IMAGES . 'cathead' . $current_path . '.gif') . '</span>':'Heading 1</span>' . $disp_block_head) . "\n"; 
      break;
          }  

So, basically what we've got is 5 different div id's, which, using CSS alone, we need to convert into a layout that looks like the 3 boxes at the bottom of THIS page. I've got 5 instead of 3, as the Types and Brands will be different for the Microphone category. (Perhaps this is unnecessary, I'm not sure).

I can explain how this works, but a pretty good rundown is HERE.

So, point me in the right direction, gods of zen!

19 Jul 2007, 12:27 PM
#2
gjh42 avatar

gjh42

Black Belt

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

Re: Coding css changes into 2 category 3 subcategory tpl_categories.php

Before proceeding with this, we need to know how you intend the overall page layout and flow to work. Do you want single column, no sideboxes, with all nav in header & footer? Do you want the whole three boxes to display at the top of every page, products or not?

The categories sidebox code will likely have to be called from another file, either tpl_main_page.php or tpl_header.php.

If you want the type and brand boxes to look/act similar for headphones and microphones, you only need a single id for type and brand. The headings can look different - give each its own "catBoxHeading#" if you want.

You will want to add```php
$content .= '<span class="catBoxHeading1">' . (file_exists(DIR_WS_TEMPLATE_IMAGES . 'cathead' . $current_path . '.gif') ? zen_image(DIR_WS_TEMPLATE_IMAGES . 'cathead' . $current_path . '.gif') . '</span>':'Price</span>' . $disp_block_head) . "\n";

$content .= '<div id="catPrice">';//bof price box
 line, for the price heading.
19 Jul 2007, 11:15 PM
#3
dvasdekis avatar

dvasdekis

New Zenner

Join Date:
Nov 2006
Posts:
70
Plugin Contributions:
0

Re: Coding css changes into 2 category 3 subcategory tpl_categories.php

As for how it's to work, sorry for not making it clearer first up. I'd like the Headphones and Microphones to be a permenant fixture at the top of the page. However, the 3 subcategory boxes would ideally disappear when you've clicked on a subcategory of product. I think people can work out how to hit 'back' or 'headphones' when they want to go back to the 3 boxes with the subcategories.

Secondly, I don't want any sideboxes on either side, Amazon-style, with both the product listings and the product details displayed along the entire width of the screen, below 'headphones, microphones'. Eventually when I learn some more PHP I might fiddle with the way that products are displayed in a list when you click a subcategory, but that's for later.

I hope I've answered everything. Thanks again!

20 Jul 2007, 5:29 PM
#4
gjh42 avatar

gjh42

Black Belt

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

Re: Coding css changes into 2 category 3 subcategory tpl_categories.php

Do you want the subcat boxes on the home page? That would mean either headphones or microphones subcats open - one or the other, not both. Or do you want a lead-in image/phrase/etc. on home page, with customers selecting h or m to begin the process? In that case, a test for $current_page_base == 'index' and ($cPath == 1 or $cPath == 2) would allow the subcat boxes to display while not displaying the grid of subcat image/titles. It looks like the file to edit will be tpl_index_categories.php, and the 'index' test will not be needed here. It is a complex file and it will take some examining to determine what parts can safely be bypassed and where box display code should go.

If you would like products displayed in a grid instead of a vertical list, get the Column Layout Grid mod in Downloads.

21 Jul 2007, 3:48 AM
#5
dvasdekis avatar

dvasdekis

New Zenner

Join Date:
Nov 2006
Posts:
70
Plugin Contributions:
0

Re: Coding css changes into 2 category 3 subcategory tpl_categories.php

gjh42:

Do you want the subcat boxes on the home page? That would mean either headphones or microphones subcats open - one or the other, not both. Or do you want a lead-in image/phrase/etc. on home page, with customers selecting h or m to begin the process? In that case, a test for $current_page_base == 'index' and ($cPath == 1 or $cPath == 2) would allow the subcat boxes to display while not displaying the grid of subcat image/titles. It looks like the file to edit will be tpl_index_categories.php, and the 'index' test will not be needed here. It is a complex file and it will take some examining to determine what parts can safely be bypassed and where box display code should go.

If you would like products displayed in a grid instead of a vertical list, get the Column Layout Grid mod in Downloads.
Nope. I'm quite happy for Headphones to be open on the index. They're by far my dominant seller, after all, and I want to minimise the clicks that people need to buy anything, hence this layout.

I found that admin setting where I can set the front page to a cartain category so either I can just make the index redirect to the Headphones category, or I could integrate it in the index file. Making it a simple redirect would be fine for now, is what I'm thinking.

22 Jul 2007, 1:05 AM
#6
dvasdekis avatar

dvasdekis

New Zenner

Join Date:
Nov 2006
Posts:
70
Plugin Contributions:
0

Re: Coding css changes into 2 category 3 subcategory tpl_categories.php

dvasdekis:

I found that admin setting where I can set the front page to a cartain category so either I can just make the index redirect to the Headphones category, or I could integrate it in the index file. Making it a simple redirect would be fine for now, is what I'm thinking.
On further inspection this does not work as planned.

22 Jul 2007, 3:31 AM
#7
gjh42 avatar

gjh42

Black Belt

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

Re: Coding css changes into 2 category 3 subcategory tpl_categories.php

I think the approach that will work is to insert code in tpl_index_categories.php to require the categories sidebox output and bypass all the rest of the regular output.

This snippet from /includes/modules/column_left.php pulls the next box from the list:

require(DIR_WS_MODULES . 'sideboxes/' . $column_left_display->fields['layout_box_name']);

We already know which one we want, so we can change this to

require(DIR_WS_MODULES . 'sideboxes/categories.php');

This then uses the zen_category_tree() function to build the categories tree and calls tpl_categories.php to format the output. I'm not sure if another file needs to be called to actually display the output on the page, or if that is already implicit.

In /includes/templates/your_template/templates/tpl_index_categories.php, find at the top```php

  • @version $Id: tpl_index_categories.php 4678 2006-10-05 21:02:50Z ajeh $
    */
    ?>
<div class="centerColumn" id="indexCategories"> <?php if ($show_welcome == true) { ?> <h1 id="indexCategoriesHeading"><?php echo HEADING_TITLE; ?></h1> ```and change to```php * @version $Id: tpl_index_categories.php 4678 2006-10-05 21:02:50Z ajeh $ */ ?> <div class="centerColumn" id="indexCategories"> <?php if ($cPath == '1' or $cPath == '2') { //show 3 subcat boxes require(DIR_WS_MODULES . 'sideboxes/categories.php'); } else { //standard output ?> <?php if ($show_welcome == true) { ?> <h1 id="indexCategoriesHeading"><?php echo HEADING_TITLE; ?></h1> ``` At the end of the file, find```php <?php $show_display_category->MoveNext(); } // !EOF ?> </div> ```and change to```php <?php $show_display_category->MoveNext(); } // !EOF } //show 3 subcat boxes - standard output ?> </div> ``` I have not tested this myself, so if it doesn't work right, post what you did and details of the results (& a jpg screenshot if possible). If some output comes through in the center column to start with, I will be happy. We can take it from there. Actually, I hope someone with more experience here can take over, as I am getting down to the wire on preparations for a major trip and shouldn't be spending much more time here for a few weeks.
22 Jul 2007, 7:27 AM
#8
dvasdekis avatar

dvasdekis

New Zenner

Join Date:
Nov 2006
Posts:
70
Plugin Contributions:
0

Re: Coding css changes into 2 category 3 subcategory tpl_categories.php

Below are the result's of Glenn's post.


When the top bar is clicked, the subcategories display in the middle! Good times and happy days!
However, when we set the global status of the left sidebox column to 0, we get...

Looking good! But then, clicking on Headphones, we get...

Of course, I assume we can just go Display: none in CSS to fix this, and that it is to be expected.

The site, with the column turned on, is available at http://test.headsonic.com.

Thanks again Glenn! Every second of help you've given me is very, very appreciated! Best of luck on your trip!

24 Jul 2007, 12:08 AM
#9
dvasdekis avatar

dvasdekis

New Zenner

Join Date:
Nov 2006
Posts:
70
Plugin Contributions:
0

Re: Coding css changes into 2 category 3 subcategory tpl_categories.php

Great Success! I managed to work enough display: none; clauses into CSS to eradicate the left column on the index page, but have the categories appear when Headphones or Microphones is clicked. I'm going to try and fumble my way through the CSS now, and hopefully lay it out in a way that will let me put some images in soon.

25 Jul 2007, 10:14 AM
#10
dvasdekis avatar

dvasdekis

New Zenner

Join Date:
Nov 2006
Posts:
70
Plugin Contributions:
0

Re: Coding css changes into 2 category 3 subcategory tpl_categories.php

Now, I've gotten it to a stage where all it is is a list of subcategory links within divs in vertical order, but so far my forays into CSS div creation have produced nothing like what I'm trying to achieve. For instance, inputting all the paddings as I've got them in my PSD file just gives me an oddly-shaped grey rectangle, with the links to the right side of it.

Is there a good place to start anywhere?

25 Jul 2007, 4:50 PM
#11
gjh42 avatar

gjh42

Black Belt

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

Re: Coding css changes into 2 category 3 subcategory tpl_categories.php

You will want to turn off category counts, and set subcategories indent and separator to blank, in your admin. Also turn off new products etc. instead of using css to blank them out.

This CSS will give you a start on arranging your subcat boxes.

/**
* CSS Stylesheet for Categories Dressing examples
* copy/modify desired sections into main stylesheet, integrating with existing declarations, and delete this file
* Categories Dressing v2.0   Glenn Herbert (gjh42)  2007-07-13
*/

/*
edits for headsonics 2007-07-25
*/
#navCatTabs a.category-top {color: #000000;}

#indexCategories .catPriceHeading1 { 
    font-family: 'times new roman', serif;
    font-weight: bold;
    font-size: 1.4em;
    color: #335511; 
    background-color: #ff66ff;
    /*background-image: url(../images/catheadbg1.gif); */ /*uncomment to use background image with or without coded text*/
    /*height: 23px; */ /*uncomment to use background image without coded text*/
    display: block;
    padding: 0.3em 0.4em;
    margin-top: 2px;
    margin-bottom: 2px;
    }
#indexCategories .catTypeHeading1 { 
    font-family: 'times new roman', serif;
    font-weight: bold;
    font-size: 1.4em;
    color: #335511; 
    background-color: #ff66ff;
    /*background-image: url(../images/catheadbg1.gif); */ /*uncomment to use background image with or without coded text*/
    /*height: 23px; */ /*uncomment to use background image without coded text*/
    display: block;
    padding: 0.3em 0.4em;
    margin-top: 2px;
    margin-bottom: 2px;
    }  
#indexCategories .catBrandHeading1 { 
    font-family: 'times new roman', serif;
    font-weight: bold;
    font-size: 1.4em;
    color: #335511; 
    background-color: #ff66ff;
    /*background-image: url(../images/catheadbg1.gif); */ /*uncomment to use background image with or without coded text*/
    /*height: 23px; */ /*uncomment to use background image without coded text*/
    display: block;
    padding: 0.3em 0.4em;
    margin-top: 2px;
    margin-bottom: 2px;
    }    


/*display all cat box links as block*/
#indexCategories a {
    background-repeat: no-repeat;
    display: block;
    }
	
/*example for individual category as bg image*/
a.catBg25 {
    background-image: url(../images/catbg25.gif);
    height: 30px;
    }

a.catBg25:hover {
    background-image: url(../images/catbg25hover.gif);
    }
	
#indexCategories a.category-subs-text, #indexCategories a.category-products-text  {
    /*background-color: #ff69ff;*/
    color: #6699aa;  
    /*margin: 0.2em 0;*/
    /*padding: 0.2em 0.3em;*/
    } 

#indexCategories a.category-subs-text:hover, #indexCategories a.category-products-text:hover  {
    /*background-color: #ff69ff;*/
    color: #ff9966;  
    /*margin: 0.2em 0;*/
    /*padding: 0.2em 0.3em;*/
    } 

#indexCategories #catPrice { position: absolute; top: 300px; left: 100px; width: 170px; height: 180px; border: 2px solid #cacaca; padding: 10px;}

#indexCategories #catType { position: absolute; top: 300px; left: 350px; width: 170px; height: 180px; border: 2px solid #cacaca; padding: 10px;}

#indexCategories #catBrand { position: absolute; top: 300px; left: 600px; width: 170px; height: 180px; border: 2px solid #cacaca; padding: 10px;}
29 Jul 2007, 4:57 AM
#12
dvasdekis avatar

dvasdekis

New Zenner

Join Date:
Nov 2006
Posts:
70
Plugin Contributions:
0

Re: Coding css changes into 2 category 3 subcategory tpl_categories.php

Glenn,

Thankyou once again, as always. I've implemented all the CSS and the finished template is going up on my live site now. Every second of help you've given me has let me do a great deal of learning and work on my own, and I doubt this could have come along anywhere near as swiftly (if at all) without your help.

The one aspect of the code I don't understand in your above post is

/*example for individual category as bg image*/
a.catBg25 {
    background-image: url(../images/catbg25.gif);
    height: 30px;
    }

a.catBg25:hover {
    background-image: url(../images/catbg25hover.gif);
    }

Is this intended to put the subcategory (each individual price group, each individual brand, etc.) images into the boxes? If so, how is it accessed in the php? Should I go along as per this post of your, adding spans to each subcategory?

Thanks again!

2 Sep 2007, 5:45 AM
#13
dvasdekis avatar

dvasdekis

New Zenner

Join Date:
Nov 2006
Posts:
70
Plugin Contributions:
0

Re: Coding css changes into 2 category 3 subcategory tpl_categories.php

NEVERMIND. See bottom of this post for fix.

I know its been a while, but I'm just going through a move to a new server. I'm now getting this error code on the pages where the 3 box layout should display. As far as I can see, the files in the two directories it mentions in the error codes are identical between my old working server and this new one.

Warning: main(includes/templates/wogeordie/common/) [function.main]: failed to open stream: No such file or directory in /home/vasdekis/public_html/includes/modules/sideboxes/categories.php on line 27

Warning: main(includes/templates/wogeordie/common/) [function.main]: failed to open stream: No such file or directory in /home/vasdekis/public_html/includes/modules/sideboxes/categories.php on line 27

Warning: main(includes/templates/wogeordie/common/) [function.main]: failed to open stream: No such file or directory in /home/vasdekis/public_html/includes/modules/sideboxes/categories.php on line 27

Fatal error: main() [function.require]: Failed opening required 'includes/templates/wogeordie/common/' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/vasdekis/public_html/includes/modules/sideboxes/categories.php on line 27

Any ideas?

Solution: Don't be dumb like I did and turn off the left column globally.

2 Sep 2007, 9:29 AM
#14
gjh42 avatar

gjh42

Black Belt

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

Re: Coding css changes into 2 category 3 subcategory tpl_categories.php

I really like the way your site turned out. I have just a couple of comments/suggestions you may not have thought of.

The logo alt text (displays when you hover over the logo) could be customized in /includes/languages/english/your_template/header.php, and

You might put a test around the "Home" link in the navbar to not display it on the home page. Links that lead to where you already are are bad ergonomics.

if (!$this_is_home_page) {
...home link code...
}