Forums / Templates, Stylesheets, Page Layout / Only active category with sub-categories in sidebox?

Only active category with sub-categories in sidebox?

Locked

Views: 2,671

Results 1 to 15 of 15
This thread is locked. New replies are disabled.
22 May 2007, 1:11 PM
#1
jarsa avatar

jarsa

New Zenner

Join Date:
May 2006
Posts:
45
Plugin Contributions:
0

Only active category with sub-categories in sidebox?

Is there any way to hide categories in the sidebox so that the sidebox only shows the sub-categories of active top-category. All the other top-categories should be hidden. Main page (Home) should still have all the top-categories available.

As you enter the shop you should see all the categories: for example monitors, games, dvd's etc.. You make your choise and at the next page you see only subcategories for dvd's: action, comedy....

I have tried to do this with css and templates and it's easy to get top-categories off, but the main page remains as a problem.

Thanks,
Jarsa

22 May 2007, 1:17 PM
#2
thepatch avatar

thepatch

Zen Follower

Join Date:
Sep 2006
Posts:
281
Plugin Contributions:
0

Re: Only active category with sub-categories in sidebox?

Are you saying that you want to hide all the other top categories once they go into a sub category?

Samuel Turnmire
co-Founder
geekFoundry

22 May 2007, 1:29 PM
#3
gjh42 avatar

gjh42

Black Belt

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

Re: Only active category with sub-categories in sidebox?

I don't think forcing all navigation through the home page is generally a good idea, but if that's what you really want...

Just a preliminary thought -

There are tags for the active category and subs. You could use those in your main stylesheet with display: none; and make an index_home.css (in the same folder) with display: block; or inline;...
(Clarification: Set everything but those tags to display none or block.)

Now I don't know without studying the file for it whether this will get rid of the space or just the text. If the latter, code work will be required. I'll look at it and get back; I think a simplified version of the code developed in the Parent Categories Separated In 3 sideboxes will work.

22 May 2007, 3:42 PM
#4
gjh42 avatar

gjh42

Black Belt

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

Re: Only active category with sub-categories in sidebox?

This is the line in tpl_categories.php that decides whether a category gets displayed:

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 {

This line has a test for the current category:

if ($box_categories_array[$i]['current']) {

A subcategory will have a _ in the cPath, but a top category won't.

So you could add a test for the category being a top cat and not current, and skip it:

or (!ereg("_",$cPath) and !$box_categories_array[$i]['current'])

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) or (!ereg("_",$cPath) and !$box_categories_array[$i]['current'])) {
        // skip if this is for the document box (==3) or non-current top cat(_, current)
      } else {

You could also use

or ($box_categories_array[$i]['top'] == 'true' and !$box_categories_array[$i]['current'])

as a test.

23 May 2007, 11:40 AM
#5
jarsa avatar

jarsa

New Zenner

Join Date:
May 2006
Posts:
45
Plugin Contributions:
0

Re: Only active category with sub-categories in sidebox?

Thanks for replies,:clap:

CSS solution leaves empty spaces if I did everything correctly.:wacko:

This template thing is easy and great way to solve problem. Thanks! But if I didn't mess something up the Home page sidebox looses it's categories too. This is not something too serious for me though, because the main page is going to be different anyway. But if there is another just as simple and elegant solution for Home page, I'll be listening. :D

23 May 2007, 1:49 PM
#6
gjh42 avatar

gjh42

Black Belt

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

Re: Only active category with sub-categories in sidebox?

Oops! The code I had put in for discriminating between home page & others got lost while reworking the approach to category discrimination. This occurred to me last night. To fix this, add

and !$this_is_home_page

to the test:```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) or (!ereg("",$cPath) and !$box_categories_array[$i]['current'] and !$this_is_home_page)) {
// skip if this is for the document box (==3) or non-current top cat(
, current) & not homepg
} else {

24 May 2007, 9:23 AM
#7
jarsa avatar

jarsa

New Zenner

Join Date:
May 2006
Posts:
45
Plugin Contributions:
0

Re: Only active category with sub-categories in sidebox?

Ok Glenn, it works beatifully and it was great solution. What more can I say than Thank You. And I hope we all can learn from you how to help fellow Zenners.:cheers:

-Jarsa-

28 May 2007, 4:33 PM
#8
reza avatar

reza

Zen Follower

Join Date:
Aug 2006
Posts:
166
Plugin Contributions:
0

Re: Only active category with sub-categories in sidebox?

gjh42:

Oops! The code I had put in for discriminating between home page & others got lost while reworking the approach to category discrimination. This occurred to me last night. To fix this, add

and !$this_is_home_page

to the test:```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) or (!ereg("",$cPath) and !$box_categories_array[$i]['current'] and !$this_is_home_page)) {
// skip if this is for the document box (==3) or non-current top cat(
, current) & not homepg
} else {


hi gjh24 
excuse me, this last one? I didn't get exactly,
actually, I have installed multisite zen 1.3.7, and if you know, this module filter the categories for the site that you want to be shown.
but the question is now, I want to have the category name as the name of the site, because each category has many subcategory, so, I like to disapear showing top category name in the side box, but the first high level category name that is shown , be the subcategory mevel 1 etc.

I tried to replace your code, in template default/sideboxes, but it didn't change any thing on my fresh zen cart1.3.7 without multisite module. I did put this changed file also in mytemplate/sidebox, and the result was nothing.
any help,
29 May 2007, 7:08 AM
#9
gjh42 avatar

gjh42

Black Belt

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

Re: Only active category with sub-categories in sidebox?

I know nothing about the inner workings of the multisite mod, and if it uses the same sort of code for discrimination, fitting the two purposes together could be very tricky.

I would need to see your site to know just what you have done. Can you post a link?

29 May 2007, 12:37 PM
#10
jarsa avatar

jarsa

New Zenner

Join Date:
May 2006
Posts:
45
Plugin Contributions:
0

Re: Only active category with sub-categories in sidebox?

Here again with new problems, :(

everything works fine until you visit information pages etc. -> categories are empty again. Now, it should be fairly easy to get all categories to sidebox (homepage style), but how to get just the catalog where visitor were before information pages?

29 May 2007, 4:47 PM
#11
gjh42 avatar

gjh42

Black Belt

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

Re: Only active category with sub-categories in sidebox?

That is an inherent problem with filtering category display by active category: when not in a category-type page, there is no active category, so no way for the system to decide what to display.

This is a deep structural problem, as the category display filtering is happening on a list generated anew with each page view, and simply setting a global variable in tpl_categories.php won't put the proper subcategories in the list to be filtered.

It may be possible to change the system behavior to remember the previous list unless on a category page or home page, but that is a part of the code where I have never ventured and wouldn't know what the ramifications of changes might be.

This line in tpl_main_page.php ```php
// the following IF statement can be duplicated/modified as needed to set additional flags
if (in_array($current_page_base,explode(",",'list_pages_to_skip_all_right_sideboxes_on_here,separated_by_commas,and_no_spaces')) ) {
$flag_disable_right = true;
}

```php
// the following IF statement can be duplicated/modified as needed to set additional flags
$flag_full_cat = false;
  if (in_array($current_page_base,explode(",",'list_pages_to_show_regular_categories_menu_on_here,separated_by_commas,and_no_spaces')) ) {
    $flag_full_cat = true;
  }
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) or (!ereg("_",$cPath) and !$box_categories_array[$i]['current'] and !$flag_full_cat)) {
        // skip if this is for the document box (==3) or non-current top cat(_, current) & not in full cat list
      } else {  
30 May 2007, 12:58 PM
#12
jarsa avatar

jarsa

New Zenner

Join Date:
May 2006
Posts:
45
Plugin Contributions:
0

Re: Only active category with sub-categories in sidebox?

It seems to work with flag and ```php
if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or (!$box_categories_array[$i]['top'] and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1) or ($box_categories_array[$i]['top']=='true' and !$box_categories_array[$i]['current'] and !$this_is_home_page and !$flag_full_cat)) {
// skip if this is for the document box (==3) or non-current top cat(_, current) & not listedpg
} else {



 So I just added that "and !flag_full_cat" to existing code. Now all top-categories are visible at defined pages. I couldn't get it working other way and actually this is fine. 

I have also learned my lesson and I'm just cautiously optimistic with this solution until all the testing is done. Well at least I learned another valuable trick with flags. Thanks for that! :D
10 Oct 2007, 5:05 AM
#13
milkyway avatar

milkyway

Inactive

Join Date:
Aug 2006
Location:
Singapore
Posts:
167
Plugin Contributions:
1

Re: Only active category with sub-categories in sidebox?

Glenn, I use your code as basis, and other suggestion works guys. Thanks for all.
Anyhow there is still some improvement we seek for our category,
We need to show only sub-sub-category listing without the upper level sub-category shown, or other sub-sub-categories.

Here you can check what we have so far:

http://www.zen4me.com/projects/jack/index.php?main_page=index&cPath=7_10

You can see that the page is sub-sub-category page 'Beer Glasses'

'Beer Glasses' is under 'Glassware'

However in that page we still can see 'Glassware' (upper level sub-category) and also other sub-sub-categories under 'Glassware' such as 'By Brand', 'Coktail Glassware' etc

We would like to remove the upper level sub-category 'Glassware' and also other sub-sub-category, so in that page we will only see 'Glassware' and its subs without any other categories.

Alos this is another example for a category named 'Test 3' which is under 'Beer Glasses', we also want to show only 'Test 3' category on the left sidebox.

http://www.zen4me.com/projects/jack/index.php?main_page=index&cPath=7_10_28

I have spent few days cracking the code and somehow I found a dead end.

Really appreciate all helps.

Thanks!

Responsive ZenCart Templates that automatically adapt itself with iPad, iPhone, BlackBerry, Androids and any monitor screen size
Buy a coffee for Zen-Cart devs. http://www.zen-cart.com/donate

10 Oct 2007, 8:33 AM
#14
gjh42 avatar

gjh42

Black Belt

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

Re: Only active category with sub-categories in sidebox?

This is easy to change, though it may require several added tests to work as desired.

I need to clarify all the desired actions.

  • Not show top cats or non-current first-level subcats at all.
  • Not show sub-subcats that are not current when a sub-subcat is open displaying sub-sub-subcats.
  • Any others?

Change
or (!ereg("",$cPath) and !$box_categories_array[$i]['current'])
to
or (!ereg("
.*_",$cPath) and !$box_categories_array[$i]['current'])

to skip top cats and subcats which are not current.

Add
or (!ereg("_",$box_categories_array[$i]['path']))
to skip all top cats.

Add
or (ereg(".*",$cPath) and (!ereg(".*.*_",$box_categories_array[$i]['path']) and !$box_categories_array[$i]['current']))
to skip all non-active sub-subcats when at the sub-subcat 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) or (((!ereg("_.*_",$cPath) and !$box_categories_array[$i]['current']) or (!ereg("_",$box_categories_array[$i]['path'])) or (ereg("_.*_",$cPath) and (!ereg("_.*_.*_",$box_categories_array[$i]['path']) and !$box_categories_array[$i]['current']))) and !$flag_full_cat)) {
        // skip if this is for the document box (==3) or non-current top cat(_, current) & not in full cat list
      } else {   
```This is not yet tested and may require some tweaking. Let me know how it works.
3 Nov 2007, 5:29 AM
#15
milkyway avatar

milkyway

Inactive

Join Date:
Aug 2006
Location:
Singapore
Posts:
167
Plugin Contributions:
1

Re: Only active category with sub-categories in sidebox?

At the end after discussion with my client, I use part of the code and modify a bit to display non-active sub-category and upper-level category, while keeping other non-related upper level sub-category and top level category hidden.

It works like charm, thanks so much for your help!

Responsive ZenCart Templates that automatically adapt itself with iPad, iPhone, BlackBerry, Androids and any monitor screen size
Buy a coffee for Zen-Cart devs. http://www.zen-cart.com/donate