Forums / Templates, Stylesheets, Page Layout / Parent Categories Separated In 3 sideboxes

Parent Categories Separated In 3 sideboxes

Locked

Views: 18,939

Results 41 to 60 of 70
This thread is locked. New replies are disabled.
4 Apr 2008, 6:35 AM
#41
gjh42 avatar

gjh42

Black Belt

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

Parent Categories Separated In 3 sideboxes

A quick way to include all subcategories of a particular top cat is to type cast the value as an integer; any numbers following an _ will be discarded.

$cPTest = (int)str_replace("cPath=","",$box_categories_array[$i]['path']);
if(in_array($cPTest, explode(",",'3,7,7_25'))) {
  // code to be executed
}  

With three boxes to display different categories, copy this code into each one and adjust the numbers to reflect the desired top categories for that box.

For actual use in a version of tpl_categories.php, find thisphp 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 { and change to this ```php
$cPTest = (int)str_replace("cPath=","",$box_categories_array[$i]['path']);
if ((!in_array($cPTest, explode(",",'3,7,7_25'))) or 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 {

25 May 2008, 11:39 AM
#42
candylea avatar

candylea

New Zenner

Join Date:
Jun 2007
Posts:
54
Plugin Contributions:
0

Re: Parent Categories Separated In 3 sideboxes

Hi

I have walked away for awhile try'd almost every expanded cat Mod out there, Couldn't get any of them to work.

So I did your plan moved all cats to the top and used your code and it all works great. You have no idea how thankful I am for you help.

Thank you

15 Jul 2008, 10:30 AM
#43
crazycucumber avatar

crazycucumber

Zen Follower

Join Date:
Jan 2006
Posts:
403
Plugin Contributions:
0

Re: Parent Categories Separated In 3 sideboxes

hey Glenn (GJH42) seems your quite an authority on the categories manipulation.

Do you know if it is possible to use the methods you have described in the posts above to have the category sidebox that only displays the sub cats of the top level you are in ?

You would chose the top level using the Category tabs at the top of the page , then the categories sidebox just show the subs of that top level one your in .

thanks for any advice.

Various Zen cart sites !

15 Jul 2008, 1:08 PM
#44
gjh42 avatar

gjh42

Black Belt

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

Re: Parent Categories Separated In 3 sideboxes

That's very easy.

In /includes/templates/your_template/sideboxes/tpl_categories.php, find this```php
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 {

and add

substr_count($box_categories_array[$i]['path'],'_') == 0 or

to the if test to get this
```php
// subcat limit 2007-12-20
      if (substr_count($box_categories_array[$i]['path'],'_') == 0 or 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 { 

The number of underscores in $box_categories_array[$i]['path'] indicates the category level, with 0 being a top cat.

The code can also be used to hide lower level subcats, with

$box_categories_array[$i]['path'] > 1

For more discussion of this, see the original thread Hide top category - Skip to subcategories.

15 Jul 2008, 4:02 PM
#45
crazycucumber avatar

crazycucumber

Zen Follower

Join Date:
Jan 2006
Posts:
403
Plugin Contributions:
0

Re: Parent Categories Separated In 3 sideboxes

Cheers pal that works great .

Do you have examples of others that have done it ? just wanted to see what they do for the home page , maybe put another if statement in to ignore if home page ?

can i also ask if I wanted to change the Sidebox title to the top level cat ...

I assume i would change this bit

$title = BOX_HEADING_CATEGORIES;

But not sure what to put in there . Thanks

Various Zen cart sites !

15 Jul 2008, 11:23 PM
#46
gjh42 avatar

gjh42

Black Belt

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

Re: Parent Categories Separated In 3 sideboxes

The simplest way to deal with this is to make an exception for the current top cat, so that it displays in the sidebox. Then it can be styled to look like a box title, and the real box title can be hidden with CSS.

change the new code to

(substr_count($box_categories_array[$i]['path'],'_') == 0 and !$box_categories_array[$i]['current']) or

and add it to the if test to get this

// subcat limit 2007-12-20
      if ((substr_count($box_categories_array[$i]['path'],'_') == 0 and !$box_categories_array[$i]['current']) or 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 {  
18 Jul 2008, 9:17 PM
#47
triplexxx avatar

triplexxx

New Zenner

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

Re: Parent Categories Separated In 3 sideboxes

hello i been trying too many diferents ways but is not working for me can anybody help me with this

i try and i want this like from crazycucumber post#43

Do you know if it is possible to use the methods you have described in the posts above to have the category sidebox that only displays the sub cats of the top level you are in ?

You would chose the top level using the Category tabs at the top of the page , then the categories sidebox just show the subs of that top level one your in .

i Glenn has the anwser but i cant figure out :(

one of my top categories is 2
TOP Categorie
2

Subs
2_7
2_8
2_9

where i put this?

from Glenn

That's very easy.

In /includes/templates/your_template/sideboxes/tpl_categories.php, find this
PHP Code:
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 {

and add

substr_count($box_categories_array[$i]['path'],'_') == 0 or

to the if test to get this

PHP Code:
// subcat limit 2007-12-20
if (substr_count($box_categories_array[$i]['path'],'_') == 0 or 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 {

The number of underscores in $box_categories_array[$i]['path'] indicates the category level, with 0 being a top cat.

The code can also be used to hide lower level subcats, with

$box_categories_array[$i]['path'] > 1

i try exactly how glenn explain but im only getting errors blank pages....im only see my header

thanks

20 Jul 2008, 10:55 AM
#49
triplexxx avatar

triplexxx

New Zenner

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

Re: Parent Categories Separated In 3 sideboxes

hello glenn.....this is what i have right now

<?php /** * Side Box Template * * @package templateSystem * @copyright Copyright 2003-2006 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license <http://www.zen-cart.com/license/2_0.txt> GNU Public License V2.0 * @version $Id: tpl_categories.php 4162 2006-08-17 03:55:02Z ajeh $ */ $content = ""; $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">' . "\n"; for ($i=0;$i<sizeof($box_categories_array);$i++) { /* test for cats to display */ if ($box_categories_array[$i]['path'] == ('cPath=2' or 'cPath=2_7' or 'cPath=2_8' or 'cPath=2_9')) { 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=2'): // $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'; } // subcat limit 2007-12-20 if (substr_count($box_categories_array[$i]['path'],'2') == 0 or zen_get_product_types_to_category($box_categories_array[$i]['path']) == 2 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1)) { // skip if this is for the document box (==2) } else { $content .= '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">'; if ($box_categories_array[$i]['current']) { if ($box_categories_array[$i]['has_sub_cat']) { $content .= '<span class="category-subs-parent">' . $box_categories_array[$i]['name'] . '</span>'; } else { $content .= '<span class="category-subs-selected">' . $box_categories_array[$i]['name'] . '</span>'; } } else { $content .= $box_categories_array[$i]['name']; } if ($box_categories_array[$i]['has_sub_cat']) { $content .= CATEGORIES_SEPARATOR; } $content .= '</a>'; if (SHOW_COUNTS == 'true') { if ((CATEGORIES_COUNT_ZERO == '1' and $box_categories_array[$i]['count'] == 0) or $box_categories_array[$i]['count'] >= 1) { $content .= CATEGORIES_COUNT_PREFIX . $box_categories_array[$i]['count'] . CATEGORIES_COUNT_SUFFIX; } } $content .= '<br />' . "\n"; } } /* end cat display test */ /* clubewear for cats to display */ if ($box_categories_array[$i]['path'] == ('cPath=1' or 'cPath=1_3')) { 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=1'): // $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'; } // subcat limit 2007-12-20 if (substr_count($box_categories_array[$i]['path'],'1') == 0 or zen_get_product_types_to_category($box_categories_array[$i]['path']) == 1 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1)) { // skip if this is for the document box (==1) } else { $content .= '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">'; if ($box_categories_array[$i]['current']) { if ($box_categories_array[$i]['has_sub_cat']) { $content .= '<span class="category-subs-parent">' . $box_categories_array[$i]['name'] . '</span>'; } else { $content .= '<span class="category-subs-selected">' . $box_categories_array[$i]['name'] . '</span>'; } } else { $content .= $box_categories_array[$i]['name']; } if ($box_categories_array[$i]['has_sub_cat']) { $content .= CATEGORIES_SEPARATOR; } $content .= '</a>'; if (SHOW_COUNTS == 'true') { if ((CATEGORIES_COUNT_ZERO == '1' and $box_categories_array[$i]['count'] == 0) or $box_categories_array[$i]['count'] >= 1) { $content .= CATEGORIES_COUNT_PREFIX . $box_categories_array[$i]['count'] . CATEGORIES_COUNT_SUFFIX; } } $content .= '<br />' . "\n"; } } /* end cat display clubwear */ } if (SHOW_CATEGORIES_BOX_SPECIALS == 'true' or SHOW_CATEGORIES_BOX_PRODUCTS_NEW == 'true' or SHOW_CATEGORIES_BOX_FEATURED_PRODUCTS == 'true' or SHOW_CATEGORIES_BOX_PRODUCTS_ALL == 'true') { // display a separator between categories and links if (SHOW_CATEGORIES_SEPARATOR_LINK == '1') { $content .= '<hr id="catBoxDivider" />' . "\n"; } if (SHOW_CATEGORIES_BOX_SPECIALS == 'true') { $show_this = $db->Execute("select s.products_id from " . TABLE_SPECIALS . " s where s.status= 1 limit 1"); if ($show_this->RecordCount() > 0) { $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_SPECIALS) . '">' . CATEGORIES_BOX_HEADING_SPECIALS . '</a>' . '<br />' . "\n"; } } if (SHOW_CATEGORIES_BOX_PRODUCTS_NEW == 'true') { // display limits // $display_limit = zen_get_products_new_timelimit(); $display_limit = zen_get_new_date_range(); $show_this = $db->Execute("select p.products_id from " . TABLE_PRODUCTS . " p where p.products_status = 1 " . $display_limit . " limit 1"); if ($show_this->RecordCount() > 0) { $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_PRODUCTS_NEW) . '">' . CATEGORIES_BOX_HEADING_WHATS_NEW . '</a>' . '<br />' . "\n"; } } if (SHOW_CATEGORIES_BOX_FEATURED_PRODUCTS == 'true') { $show_this = $db->Execute("select products_id from " . TABLE_FEATURED . " where status= 1 limit 1"); if ($show_this->RecordCount() > 0) { $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_FEATURED_PRODUCTS) . '">' . CATEGORIES_BOX_HEADING_FEATURED_PRODUCTS . '</a>' . '<br />' . "\n"; } } if (SHOW_CATEGORIES_BOX_PRODUCTS_ALL == 'true') { $content .= '<a class="category-links" href="' . zen_href_link(FILENAME_PRODUCTS_ALL) . '">' . CATEGORIES_BOX_HEADING_PRODUCTS_ALL . '</a>' . "\n"; } } $content .= '</div>'; ?>

i try with 2 of my categories

thank you

20 Jul 2008, 1:52 PM
#50
gjh42 avatar

gjh42

Black Belt

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

Re: Parent Categories Separated In 3 sideboxes

// subcat limit 2007-12-20
if (substr_count($box_categories_array[$i]['path'],'2') == 0 or

This is going to hide the category if there are no "2" characters in the category's cPath.

I somehow don't think this will give the results you want.

If you want to hide all of your top cats, use the code exactly as I first gave it:

if (substr_count($box_categories_array[$i]['path'],'_') == 0 or ...

18 Aug 2008, 3:52 PM
#51
crazycucumber avatar

crazycucumber

Zen Follower

Join Date:
Jan 2006
Posts:
403
Plugin Contributions:
0

Re: Parent Categories Separated In 3 sideboxes

Hi Glenn , hopefully your monitoring this thread , and I apologise for keep coming back on this one. Usually once shown I understand , this category array is very confusing ( to me )

Anyway At the moment I followed your code and it works great I have only the sub cats showing for any one top cat - the question is if I am at home page or anyother page thats not in a Cat , can I have the top cats back ?

Thanks for any help.

Mark

Various Zen cart sites !

19 Aug 2008, 8:13 AM
#52
gjh42 avatar

gjh42

Black Belt

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

Re: Parent Categories Separated In 3 sideboxes

You can add a test for cPath not blank or zero. It will have a value if you are in a category. Something like:

if (($GET[cPath] != 0 and substr_count($box_categories_array[$i]['path'],'') == 0) or ...

It may require a slightly different formulation, but this general approach should work.

19 Aug 2008, 8:39 AM
#53
crazycucumber avatar

crazycucumber

Zen Follower

Join Date:
Jan 2006
Posts:
403
Plugin Contributions:
0

Re: Parent Categories Separated In 3 sideboxes

gjh42:

You can add a test for cPath not blank or zero. It will have a value if you are in a category. Something like:

if (($GET[cPath] != 0 and substr_count($box_categories_array[$i]['path'],'') == 0) or ...

It may require a slightly different formulation, but this general approach should work.

Spot on !! :clap::clap::clap:

Thanks that is just what I needed , for anyone else needing the same as me , this is a section from my tpl_categories :-

	 
// subcat limit 2007-12-20
      if (($_GET[cPath] != 0 and substr_count($box_categories_array[$i]['path'],'_') == 0) or 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 { 
 

Thanks again .

Various Zen cart sites !

6 Sep 2008, 5:46 PM
#54
chalfontgifts avatar

chalfontgifts

Zen Follower

Join Date:
Jun 2007
Posts:
122
Plugin Contributions:
0

Re: Parent Categories Separated In 3 sideboxes

Thanks for your help on this.

I have a couple of other questions, that mayby you can help me with.

Can I set a default catagory to show when someone goes to the home page.

Also is it possible to show the current catagory selected where the catagory box title is.

A bit off the subject but I am aslo struggling to find the correct place in the stylesheet.css for the the header bar and the side box sub catagories. I want to show which catagory is currently selected, by changing colour, and also show a hover and selcted colour change in the sub catagories in the sidebox.

Thanks for any help.

Regards
Laurie

6 Sep 2008, 5:53 PM
#55
crazycucumber avatar

crazycucumber

Zen Follower

Join Date:
Jan 2006
Posts:
403
Plugin Contributions:
0

Re: Parent Categories Separated In 3 sideboxes

chalfontgifts:

Thanks for your help on this.

I have a couple of other questions, that mayby you can help me with.

Can I set a default catagory to show when someone goes to the home page.

This is done in the admin / Config / layout settings

Main Page - Opens with Category = enter the cat ID in here

chalfontgifts:

Also is it possible to show the current catagory selected where the catagory box title is.

Thanks for any help.

Regards
Laurie

I tried to do this to never did find a way to do it and gave up for the time being , but would be interested in a soldi way of achieving this as it should be easy enough to have a dynamic language define to sort it out.

Good luck !

Various Zen cart sites !

7 Sep 2008, 4:41 PM
#57
gjh42 avatar

gjh42

Black Belt

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

Re: Parent Categories Separated In 3 sideboxes

For the cetegory selected/hover indication, look at the /classic/ stylesheet. There is a section for parent/child categories which shows the classes you can address.

16 Sep 2008, 3:16 PM
#58
00goat avatar

00goat

New Zenner

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

Re: Parent Categories Separated In 3 sideboxes

Well, I was really sure I could get it working without assistance... It does work, but not on the home page, and I'm seriously stumped.

I'm going for the "subcats only" variant here, one top category per box. The relevant snippets of code are below:

  /* test for cats to display */
    if(in_array(str_replace("cPath=","",$box_categories_array[$i]['path']), explode(",",'2,2_4,2_5'))) {

So only Cpath 2 and the two subcats that are set up at the moment... fairly simple.

// subcat limit 2007-12-20
      if (substr_count($box_categories_array[$i]['path'],'_') == 0 or 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 { 

And the subcat code, which works. Except the box shows empty on the home page. If I go to the top category listing, or a product, or anywhere else, I get just the two subcats in the box as I want it.

How is this possible? Thanks in advance for any advice.

16 Sep 2008, 8:31 PM
#59
gjh42 avatar

gjh42

Black Belt

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

Re: Parent Categories Separated In 3 sideboxes

When you are on the home page, you haven't chosen a category (unless you have set "Main Page opens with" to a specific category); therefore, $cPath will be empty and none of your chosen cats will display.

This bit of code
if (substr_count($box_categories_array[$i]['path'],'_') == 0
skips all top categories in the display all the time.

The
if(in_array(
already only displays the categories or subs you specify. Since you don't want any top cats, eliminate the substr_count( part, and eliminate the 2, in the explode( function.

16 Sep 2008, 8:41 PM
#60
gjh42 avatar

gjh42

Black Belt

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

Re: Parent Categories Separated In 3 sideboxes

OK, a bit of clarification.
You have done the "separate boxes" cloning bit?
And you are wanting to display the subcats of one category in one of the boxes, all the time?

Do you have an expanded categories mod installed? If not, there will be no subcats in the category tree to display unless you are in the particular top cat.