Forums / Templates, Stylesheets, Page Layout / subcategories only in sidebox main categories top

subcategories only in sidebox main categories top

Locked

Views: 5,966

Results 1 to 20 of 28
This thread is locked. New replies are disabled.
5 Jun 2008, 6:34 PM
#1
sckwooral avatar

sckwooral

New Zenner

Join Date:
Mar 2008
Posts:
18
Plugin Contributions:
0

subcategories only in sidebox main categories top

I would like to display only the subcategories for a category in a left sidebox. So, basically, you click on a category (horizontal top menu which I have working just fine) and on that specific category page the subcategories are listed in a sidebox and the first subcategory's product items fill up the center column.

There are a lot of posts related to sideboxes, menu trees etc but after hours of reading through and trying a few I still can't seem to figure it out.

Any help, links to solutions in the forum, etc. appreciated!

5 Jun 2008, 8:17 PM
#2
gjh42 avatar

gjh42

Black Belt

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

Re: subcategories only in sidebox main categories top

The easiest way to do this is probably by adding a switch that suppresses output of any category that is not current and a subcat.
Find this line in /includes/templates/your_template/sideboxes/tpl_categories.php```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
$current_top = false;
if ((int)str_replace("cPath=","",$box_categories_array[$i]['path']) == $_GET['cPath']) { //top cat of path is active
$current_top = true;
}

above it, and

($current_top == false) or ($box_categories_array[$i]['top'] == 'true') or
inside it to get```php
$current_top = false;
if ((int)str_replace("cPath=","",$box_categories_array[$i]['path']) == $_GET['cPath']) { //top cat of path is active
$current_top = true;
}
if (($current_top == false) or ($box_categories_array[$i]['top'] == 'true') 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 {

I haven't tested this yet, so try it and let me know how it works. If it needs tweaking, I'll take care of it.

6 Jun 2008, 12:35 PM
#3
sckwooral avatar

sckwooral

New Zenner

Join Date:
Mar 2008
Posts:
18
Plugin Contributions:
0

Re: subcategories only in sidebox main categories top

Hey - that's great!

I need to add some more subcategories and products to make sure it's working across the board but it appears to work.

I originally plugged the code into the Categories Dressing tpl_categories.php page that I was working with and it did not work - everything under the top category tab nav disappeared, from the breadcrumbs down. I replaced the tpl_categories with the default and applied your change and this is exactly what I was looking for. Since I don't need the Categories Dressing code I don't mind reverting back.

I'll be making changes to this as the day progresses but for anyone checking this post the original change stated above supplies a Category Specific - Subcategory Side Box that has the "Categories" title on default blue, a list of the Subcategories, and then "New Products", "All Products" followed by the green bottom. (When I'm done styling it will be slightly different than that).

Link to test page:
http://infullfig.com/index.php?main_page=product_info&cPath=5_7&products_id=1

Thanks!

6 Jun 2008, 5:33 PM
#4
gjh42 avatar

gjh42

Black Belt

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

Re: subcategories only in sidebox main categories top

Glad to see it's working! And it looks really good.

I noticed something that should be making it malfunction, but it is not malfunctioning...
The

if ((int)str_replace("cPath=","",$box_categories_array[$i]['path']) == $_GET['cPath']) {

compares the first numbers of 'path' (before the _) with the cPath (which may include an _); this should not be equal if you are in a subcategory, but it still works as desired. I'll have to test this to find out exactly why it's working before I want it relied upon.

The line should read```php
if ((int)str_replace("cPath=","",$box_categories_array[$i]['path']) == (int)$_GET['cPath']) {

10 Jun 2008, 1:14 PM
#5
sckwooral avatar

sckwooral

New Zenner

Join Date:
Mar 2008
Posts:
18
Plugin Contributions:
0

Re: subcategories only in sidebox main categories top

that new change didn't work - everything under the top categories tab disappears completely, from breadcrumbs down. I changed the code back to the original one and it works fine.

So do you feel the original changes won't work effectively? I don't know enough about PHP to understand exactly how that string of code works.

Unfortunately, my client wants me to put the site in Under Construction mode until it's finished so if you need to take another look at how it renders let me know and I'll ask permission to post the site with dummy text and images.

And I wish I could take credit for the site design - it is pretty cool - but it was designed by my client who hands off photoshop file for me to pound into shape using css and html. This is our first ecommerce project.

10 Jun 2008, 4:01 PM
#6
gjh42 avatar

gjh42

Black Belt

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

Re: subcategories only in sidebox main categories top

Curiouser and curiouser...

The
str_replace("cPath=","",$box_categories_array[$i]['path'])
removes the "cPath=" from the beginning of the path item in the array, so the format matches the format of $_GET['cPath'].
The (int) is a shortcut way to strip the subcategories if any, by type-casting the value as an integer. That might not work the same way on $_GET['cPath'] ...?

At any rate, if it works, it works.

30 Sep 2008, 6:27 AM
#7
wildgarden avatar

wildgarden

New Zenner

Join Date:
Apr 2006
Posts:
32
Plugin Contributions:
0

Re: subcategories only in sidebox main categories top

I would also like to get this working in my site, but when I add the code suggested above, the content disappears from top menu down. I am using v 1.3.8. Any ideas?

hand screen printed clothing and accessories
https://www.wildgardendesign.com

30 Sep 2008, 7:22 AM
#8
wildgarden avatar

wildgarden

New Zenner

Join Date:
Apr 2006
Posts:
32
Plugin Contributions:
0

Re: subcategories only in sidebox main categories top

Never mind, I had inserted the code incorrectly. It's working now! yay

hand screen printed clothing and accessories
https://www.wildgardendesign.com

1 Oct 2008, 11:04 AM
#9
stoneymontana avatar

stoneymontana

New Zenner

Join Date:
Jul 2008
Posts:
15
Plugin Contributions:
0

Re: subcategories only in sidebox main categories top

hi gjh42,

i have to ask because everytime i think i found the solution its for something else.

the code solution you provide, is that to prevent subcategories from showing up above the items in the middle column underneath the breadcrumbs thing? like ie...

home::cat1

     subcat1                        subcat2                   subcat3

this is the solution i need how to keep those subcategories off and only in the left column box.

i appreciate it.
thanks,

Stoney

Give a man a light, you help that man for a night. Light him on fire and you help him for the rest of his life.

1 Oct 2008, 1:35 PM
#10
stoneymontana avatar

stoneymontana

New Zenner

Join Date:
Jul 2008
Posts:
15
Plugin Contributions:
0

Re: subcategories only in sidebox main categories top

forget it i found the solution,
i apologize but since i found it 2 hours ago and then had to rush my son to school i actually forgot the spot in the control panel that did it.

my bad.

Give a man a light, you help that man for a night. Light him on fire and you help him for the rest of his life.

8 Oct 2008, 1:22 AM
#11
wildgarden avatar

wildgarden

New Zenner

Join Date:
Apr 2006
Posts:
32
Plugin Contributions:
0

Re: subcategories only in sidebox main categories top

Ok, I have this working, but in the product detail page, the subcategory sidebox links are not showing, but are there in the product listing. Please help anyone?

hand screen printed clothing and accessories
https://www.wildgardendesign.com

13 Oct 2008, 1:05 PM
#12
gjh42 avatar

gjh42

Black Belt

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

Re: subcategories only in sidebox main categories top

Wildgarden -
You have a highly customized layout already, and without seeing your PHP to know how you have handled (apparently) transplanting the categories sidebox to the center column I wouldn't try to say what is wrong... especially as I can't see any subcategories anywhere on any page. You have top categories, but not subs.

15 Oct 2008, 2:54 AM
#13
mcanes avatar

mcanes

Zen Follower

Join Date:
May 2007
Posts:
210
Plugin Contributions:
0

Re: subcategories only in sidebox main categories top

GJH42, you helped me do something similiar to this about a year ago but I want to take it one step further and I was hoping you could help.

My site is click here, and basically what I want to do is only show the following.

In the link above I would only want to show Alabama Crimson Tide and the subcategories below it. The reason is, there are so many categories that it is very hard to tell where you are at when you come from an outside source like Google.

Can you help? I would really appreciate it.

15 Oct 2008, 5:32 AM
#14
gjh42 avatar

gjh42

Black Belt

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

Re: subcategories only in sidebox main categories top

How do you want to be able to visit other categories if only the current top cat is visible in the categories box, and top cats are not shown anywhere else?

16 Oct 2008, 1:15 AM
#15
mcanes avatar

mcanes

Zen Follower

Join Date:
May 2007
Posts:
210
Plugin Contributions:
0

Re: subcategories only in sidebox main categories top

Let use the following example... If you go to here you will be in the NFL Team Store --> Arizona Cardinals category.

Currently you see the NFL TEAM STORE that will take you to the main NFL page. You also see Arizona Carindals and it's sub-categories (Baby & Youth, Bar & Game Room, etc.). This is all good and I don't want that to change, even if you click Baby & Youth...

What I do NOT want to show is all the other teams under NFL Team Store, like Atlanta, Baltimore, Buffalo, etc.

On the NFL it isn't as bad, but if you go to a NCAA team page there are 100+ teams, making it very difficult to navigate - especially if the team you are on is below the fold and you can't see it without scrolling.

Does this make sense?

Thanks

16 Oct 2008, 7:11 AM
#16
gjh42 avatar

gjh42

Black Belt

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

Re: subcategories only in sidebox main categories top

Categories box not used in home page, so don't have to account for display there.
Sports are top cats, teams are first level subcats, product types are second level subcats, holding products.

On sport page, want current top cat & its subcats. [default is all top cats & current first subs][skip non-current top cats]

On team page, want current top cat, current first subcat & its second level subcats. [default is all top cats, all first subs of current top & all second subs of current first sub][skip non-current top cats & non-current first subs]

On product type (listing) page, want current top cat, current first subcat & its second level subcats, with current second level subcat highlighted. [default is all top cats, all first subs of current top & all second subs of current first sub, with current second sub highlighted][skip non-current top cats & non-current first subs]

$current_top = false;
$show_this = false;
if ((int)str_replace("cPath=","",$box_categories_array[$i]['path']) == $_GET['cPath']) { //top cat of path is active
//above line logically should look like this, but didn't work in previous test -----v
//if ((int)str_replace("cPath=","",$box_categories_array[$i]['path']) == (int)$_GET['cPath']) { //top cat of path is active
  $current_top = true;
  if (($box_categories_array[$i]['current']) or (substr_count($box_categories_array[$i]['path'],'_') == 2)) {
    $show_this == true;
  }
}
if (($current_top == false) or ($show_this == false) 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 {  

Shelving this for tonight because I'm too tired to think about it any more. It may work as is or may want some more tweaking - I'll look at it when fresh.

16 Oct 2008, 2:54 PM
#17
gjh42 avatar

gjh42

Black Belt

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

Re: subcategories only in sidebox main categories top

Optimized for your site's category display:

$skip_this = true;
if (($box_categories_array[$i]['current'] and $box_categories_array[$i]['top']) /*show current sport*/ or ($box_categories_array[$i]['current'] and substr_count($box_categories_array[$i]['path'],'_') == 1) /*show current team*/ or substr_count($box_categories_array[$i]['path'],'_') > 1 /*show all product types*/) {
  $skip_this = false;
}
if ($skip_this == true 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 Oct 2008, 1:56 AM
#18
mcanes avatar

mcanes

Zen Follower

Join Date:
May 2007
Posts:
210
Plugin Contributions:
0

Re: subcategories only in sidebox main categories top

Glenn, where should I put this? Do I need to change anything else or just add this? Thanks for your help

18 Oct 2008, 4:39 AM
#19
gjh42 avatar

gjh42

Black Belt

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

Re: subcategories only in sidebox main categories top

Just replace the ```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 {

18 Oct 2008, 2:29 PM
#20
mcanes avatar

mcanes

Zen Follower

Join Date:
May 2007
Posts:
210
Plugin Contributions:
0

Re: subcategories only in sidebox main categories top

Glenn, this works great... One thing though, when I go to a page like Advanced search I get the categories box but it is blank?

I don't have a Staging server to show you it on, but if you need me to I can go ahead an upload it to the production server so you can see the behavior or I can post a screen shot.

Please let me know which you prefer.

Thanks

Sean