Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Determining root category ID while in a sub-category [cPath question]

Determining root category ID while in a sub-category [cPath question]

Locked

Views: 2,469

Results 1 to 4 of 4
This thread is locked. New replies are disabled.
9 May 2009, 1:56 PM
#1
stealthify avatar

stealthify

New Zenner

Join Date:
Dec 2008
Posts:
21
Plugin Contributions:
0

Determining root category ID while in a sub-category [cPath question]

Hi there,
I need the help of a few Zen Cart guru's on this one. I know this can be done, but its just a little over the top of my head at this point (still learning).

In short, I'm trying to alter the $categories_image variable (found in the tpl_index_categories.php template file) so that it'll only display the image from the root category (no matter how deep into the sub-categories of that main category you're in).

So, for example, say I have the following category structure:

Household Supplies [ID: 1]
- Bathroom Supplies [ID: 2]
--- Toilet Supplies [ID: 3]
------ Cleaners [ID: x]
---------- Clorox [ID: x]
---------- Windex [ID: x]

------ Seat Covers [ID: x]
---------- Fluffy [ID: x]
---------- Leather [ID: x]

------ Plungers [ID: x]
---------- Super-Mario Style [ID: x]
--- Shower Supplies [ID: 4]
------ Curtains [ID: x]
---------- Pokadot [ID: x]
------ Shower Heads [ID: x]
---------- Steampunk [ID: x]
etc

Basically, I know the cPath to the 'Toilet Supplies' category would be 1_2_3, and 'Shower Supplies' would be 1_2_4.

Now, my question is how would I go about pulling just the second number (first sub-category of the main category) out of that cPath?

The goal here is so that the category icon for 'Bathroom Supplies' appears at the top of the 'Toilet Supplies' and 'Shower Supplies' category pages.

I can probably figure out the rest from there ('if' situations to determine if we're more than 2 categories deep, etc), but I'm feeling a little stumped here. Any advice?

:bigups:

9 May 2009, 2:08 PM
#2
gjh42 avatar

gjh42

Black Belt

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

Re: Determining root category ID while in a sub-category [cPath question]

$path_ids = explode('_',$_GET['cPath']);// break $cPath into array
if (count($path_ids) >= 2) {//test for subcat level
  $path_firstsub = $path_ids[1];// [1] is the second element in the array
}
9 May 2009, 2:16 PM
#3
stealthify avatar

stealthify

New Zenner

Join Date:
Dec 2008
Posts:
21
Plugin Contributions:
0

Re: Determining root category ID while in a sub-category [cPath question]

gjh42:

$path_ids = explode('_',$_GET['cPath']);// break $cPath into array
if (count($path_ids) >= 2) {//test for subcat level
$path_firstsub = $path_ids[1];// [1] is the second element in the array
}


Glenn, I owe you a drink! Or two!

I was completely over-analyzing the task at hand, thank you for simplifying it for me.

Going to run with this for a bit, I think it'll do the trick. Thank you!
9 May 2009, 2:22 PM
#4
stealthify avatar

stealthify

New Zenner

Join Date:
Dec 2008
Posts:
21
Plugin Contributions:
0

Re: Determining root category ID while in a sub-category [cPath question]

Done deal, worked like a charm.

Thanks again friend.