Zen Cart Logo
Forums / Addon Sideboxes / Expanded Category - expand only to subcat1?

Expanded Category - expand only to subcat1?

Locked

Views: 5,863

Results 1 to 18 of 18
This thread is locked. New replies are disabled.
19 Dec 2007, 11:50 PM
#1
tacoma avatar

tacoma

Zen Follower

Join Date:
Dec 2007
Posts:
125
Plugin Contributions:
0

Expanded Category - expand only to subcat1?

Using Expanded Category 2. I would like to just show category, and 1st subcategory.

I want all of the other subcategories to be hidden(collapsed).

Is there a way to do this?

Thanks.

20 Dec 2007, 8:58 AM
#2
gjh42 avatar

gjh42

Black Belt

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

Re: Expanded Category - expand only to subcat1?

Very easy. The category depth is shown in $cPath, with subcats separated by underscores _ . If it has one underscore, it is a first level subcat, two underscores = second level, etc. You can access that information for each prospective category in the list with
substr_count($box_categories_array[$i]['path'],'_')

Find this in /includes/templates/your_template/sideboxes/tpl_categories.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'],'_') > 1 or
to get
```php
     if (substr_count($box_categories_array[$i]['path'],'_') > 1 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 {
20 Dec 2007, 3:25 PM
#3
tacoma avatar

tacoma

Zen Follower

Join Date:
Dec 2007
Posts:
125
Plugin Contributions:
0

Re: Expanded Category - expand only to subcat1?

Thanks Glenn, your help is invaluable!

12 Jan 2008, 1:43 AM
#4
dexter avatar

dexter

New Zenner

Join Date:
Oct 2007
Location:
Netherlands
Posts:
36
Plugin Contributions:
0

Re: Expanded Category - expand only to subcat1?

Hiya I not sure of someone still check here but I can not find this Expanded Category 2?

And I want the Category to always show the submenu (not the products) :D

Please tell me where to get this addon!

12 Jan 2008, 7:33 AM
#5
gjh42 avatar

gjh42

Black Belt

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

Re: Expanded Category - expand only to subcat1?

The mod is called Expanded Category List (by Clydejones) and can be found in Downloads.

12 Jan 2008, 3:27 PM
#6
dexter avatar

dexter

New Zenner

Join Date:
Oct 2007
Location:
Netherlands
Posts:
36
Plugin Contributions:
0

Re: Expanded Category - expand only to subcat1?

Thanks giving it a go but it say it also will list the products :(

12 Jan 2008, 6:16 PM
#7
gjh42 avatar

gjh42

Black Belt

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

Re: Expanded Category - expand only to subcat1?

Never used it myself so can't comment... I have heard this complaint from other people, but I have also heard from people saying they use it and don't see products in their categories box.

At any rate, there is another mod called Uncollapsed Categories Tree by fragfutter (hosted on his own site) that reportedly works exactly as you want.
(It creates a sidebox id of ch_categories, so you can tell by viewing a site's source that they are using this mod.)

14 Jan 2008, 7:34 AM
#8
ronlee67 avatar

ronlee67

Totally Zenned

Join Date:
Sep 2006
Location:
Colorado Springs CO USA
Posts:
519
Plugin Contributions:
0

Re: Expanded Category - expand only to subcat1?

gjh42:

Very easy. The category depth is shown in $cPath, with subcats separated by underscores _ . If it has one underscore, it is a first level subcat, two underscores = second level, etc. You can access that information for each prospective category in the list with
substr_count($box_categories_array[$i]['path'],'_')

Find this in /includes/templates/your_template/sideboxes/tpl_categories.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 {
> substr_count($box_categories_array[$i]['path'],'_') > 1 or
> to get
> ```php
     if (substr_count($box_categories_array[$i]['path'],'_') > 1 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 {

Glenn:
I added the code but it doesn't seem to make any difference in the display of the category sidebox. I think I'm missing something here. Isn't there some place in the code where I specify how many sub-levels to limit the display? It's probably obvious to experience programmers, but my skills at php are still quite limited.

My goal is to show only the top level categories and the first sub-level below the top. No products.

Here is the way I modified the code:

 
// beg mod 2008-01-14 per forum [URL]http://www.zen-cart.com/forum/showthread.php?t=83405[/URL] post #2 author gjh42 to limit category list to 1 subcategory level.
//     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)) {
       substr_count($box_categories_array[$i]['path'],'_') > 1 or 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)) {
// end mod 2008-01-14

Thanks for any help.

Ron

14 Jan 2008, 8:12 AM
#9
ronlee67 avatar

ronlee67

Totally Zenned

Join Date:
Sep 2006
Location:
Colorado Springs CO USA
Posts:
519
Plugin Contributions:
0

Re: Expanded Category - expand only to subcat1?

gjh42 Glenn:

I caught the mistake in the previously quoted code. Had the "if" statements misplaced. Here is the correct code, but nevertheless, the problem still exists. I'm showing all category levels and products, but only want two levels.

// beg mod 2008-01-14 per forum http://www.zen-cart.com/forum/showthread.php?t=83405 post #2 author gjh42 to limit category list to 1 subcategory level.
//     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)) {
       if (substr_count($box_categories_array[$i]['path'],'_') > 1 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)) {
// end mod 2008-01-14
// skip if this is for the document box (==3)

Ron

14 Jan 2008, 3:37 PM
#10
gjh42 avatar

gjh42

Black Belt

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

Re: Expanded Category - expand only to subcat1?

The specification of sub-levels happens here:

substr_count($box_categories_array[$i]['path'],'_') > 1

In English, it counts the number of times that an _ appears in the string contained in $box_categories_array[$i]['path']. There will be one _ for each level of subcategory, so that's all the technology needed for the spec!
The whole if() statement skips the category in the list if any of the conditions is true (like the number of _ being > 1).

As to why it's not working for you, I'll have to check some more.

14 Jan 2008, 5:17 PM
#11
ronlee67 avatar

ronlee67

Totally Zenned

Join Date:
Sep 2006
Location:
Colorado Springs CO USA
Posts:
519
Plugin Contributions:
0

Re: Expanded Category - expand only to subcat1?

Are we modifying the right code? The original If statement appears to be related to special handling of Product Type 3 - General Documents.

I understand the concept of counting underscores. I was wondering if it matters whether or not Admin -> Configuration -> Layout Settings -> Category Separator between Category Name and Sub Categories is set to include an underscore.

I'm using a third party template from iChoze.com called IC-AcademeV1.2 which replaces the separator with what appears to be an image. In going over the template code, that image appears to actually be a font widget pulled up using LI commands.

I'll take a look at another template I'm using on another site and see what the differences are in this area and whether your mod to Category List Expanded works there and will let you know.

15 Jan 2008, 9:31 AM
#12
gjh42 avatar

gjh42

Black Belt

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

Re: Expanded Category - expand only to subcat1?

That line determines whether the current category in the list is going to be processed or skipped, for any of several reasons. The "documents" part is the only one that got a comment.

The underscores have nothing to do with the output in the categories box - they are a fundamental part of the PHP code and will stay as is no matter what.

15 Jan 2008, 7:22 PM
#13
ronlee67 avatar

ronlee67

Totally Zenned

Join Date:
Sep 2006
Location:
Colorado Springs CO USA
Posts:
519
Plugin Contributions:
0

Re: Expanded Category - expand only to subcat1?

gjh42:

That line determines whether the current category in the list is going to be processed or skipped, for any of several reasons. The "documents" part is the only one that got a comment.

The underscores have nothing to do with the output in the categories box - they are a fundamental part of the PHP code and will stay as is no matter what.

Thanks Glenn,

That eliminates one concern (the underscore question). Will make it much easier to troubleshoot knowing that.

I hear you regarding the code that determines whether to skip or not. Just don't understand why this won't work for me. I have another site with a different 3rd party template from a different author and it won't work with this contribution either. However, both templates involved monkey around with the bullets. One substitutes a font widget for a bullet and the other eliminates bullets altogether.

Next steps for me:

  • try the classic template just to be sure it's a compatibility problem with the 3rd party templates
  • try some of the other contributions that are supposed to do the same thing.I appreciate your help. Will post my findings here once I resolve this issue.

Ron

15 Jan 2008, 11:21 PM
#14
gjh42 avatar

gjh42

Black Belt

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

Re: Expanded Category - expand only to subcat1?

Have just tested the

substr_count($box_categories_array[$i]['path'],'_') > 1 or

addition on a fresh 1.3.7 install, and it does work as advertised. (I don't have any expanded category list mod.)

16 Jan 2008, 2:31 AM
#15
ronlee67 avatar

ronlee67

Totally Zenned

Join Date:
Sep 2006
Location:
Colorado Springs CO USA
Posts:
519
Plugin Contributions:
0

Re: Expanded Category - expand only to subcat1?

orignally posted by tacoma
Expanded Category - expand only to subcat1?
Using Expanded Category 2. I would like to just show category, and 1st subcategory.

I want all of the other subcategories to be hidden(collapsed).

Is there a way to do this?

Thanks.

gjh42:

Very easy. The category depth is shown in $cPath, with subcats separated by underscores _ . If it has one underscore, it is a first level subcat, two underscores = second level, etc. You can access that information for each prospective category in the list with
substr_count($box_categories_array[$i]['path'],'_')

Find this in /includes/templates/your_template/sideboxes/tpl_categories.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 {
> substr_count($box_categories_array[$i]['path'],'_') > 1 or
> to get
> ```php
     if (substr_count($box_categories_array[$i]['path'],'_') > 1 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 {

Glenn:
I misunderstood your first post offering the substr count code. I thought that was a modification to Clyde's Expanded Category List contribution which displays sub-categories and products at all times.

I now understand that your code modifies the original tpl_categories.php file (or a copy of same in the "custom" template folder).
When Clyde's contribution is used, we turn off categories.php in admin -> tools -> Layout Boxes Controller and turn on his categories_listing.php in it's place. Presumably this also switches to similarly named files in the classes, language, modules and template folders.

I did a WinMerge to compare tpl_categories.php and tpl_category_list_box.php and found that Clyde's tpl_categories_list_box.php is pretty much a complete rewrite and the code that your substr mod would be attached to does not exist there. Perhaps there is still a way to modify Clyde's contribution to limit the number of category sub-levels but I don't have the expertise to figure it out.

From what I can determine, your solution can't sucessfully be applied to the Expanded Category List contribution. If you get some time and want to, I hope you will look at tpl_categories_list_box.php from the contribution and see if there is a way to limit the number of sub-categories and prevent products from appearing in the Categories sidebox. It would be much appreciated. Meanwhile, thank you for the guidance. Ron

16 Jan 2008, 4:11 PM
#16
gjh42 avatar

gjh42

Black Belt

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

Re: Expanded Category - expand only to subcat1?

I guess I'm going to have to study the Expanded Category List files, and the Uncollapsed Categories Tree files too. I had been under the impression that Expanded Cats just reworked the list in categories.php, but that's obviously not the case. It certainly will be possible to make the subcat limit, I'll just have to find the spot.

Meanwhile, if Expanded Cats doesn't have a way to eliminate the products, your best bet may be to use Uncollapsed Categories Tree, which is made to do what you want.

10 Feb 2008, 9:48 PM
#17
quentinjs avatar

quentinjs

Zen Follower

Join Date:
Mar 2004
Location:
Calgary, Alberta
Posts:
289
Plugin Contributions:
0

Re: Expanded Category - expand only to subcat1?

Is this the best method if I want to show cat level 1 and 2 all the time, as well as possibly level 3/4 for a specific category chain?

10 Feb 2008, 10:01 PM
#18
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: Expanded Category - expand only to subcat1?

For people who want to limit depth level, or just showing a specific branch of the tree, this may help:

http://www.zen-cart.com/forum/showthread.php?t=88215