Forums / Templates, Stylesheets, Page Layout / Finding out what top level category a product belongs to?

Finding out what top level category a product belongs to?

Locked

Started by millo_magno on 16 Feb 2007, 2:23 AM · Views: 2,460

Results 1 to 5 of 5
This thread is locked. New replies are disabled.
16 Feb 2007, 2:23 AM
#1
millo_magno avatar

millo_magno

New Zenner

Join Date:
Nov 2006
Posts:
25
Plugin Contributions:
0

Finding out what top level category a product belongs to?

Hi,

Is there a variable or a way to return the value of what the top level category that a product belongs to?

I need to vary output depending on what main (top level) category a product belongs to.

Many thanks in advance!

16 Feb 2007, 3:04 AM
#2
gjh42 avatar

gjh42

Black Belt

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

Re: Finding out what top level category a product belongs to?

$cPath holds the path that was taken to get to the product, in the form 12_34_etc, 12 being the top category ID and 34 being the subcat if there is one (or more).

You can use the PHP function ereg to test for the first number having a certain value or values, though it doesn't output the number, just true or false. Here's a sample of how I used it: ```php
if (ereg("(^1$|^1_)",$cPath)) //wedding or sub
{
echo "<img src='../fr-136/images/frheadwed.gif' alt='The Wedding and Betrothal Collection'>";
}
elseif (ereg("(^2$|^2_)",$cPath)) //celtic or sub
...

16 Feb 2007, 8:58 AM
#3
millo_magno avatar

millo_magno

New Zenner

Join Date:
Nov 2006
Posts:
25
Plugin Contributions:
0

Re: Finding out what top level category a product belongs to?

Great!

I assume that this is global and can be used throughout any of the includes. I'll check it out and give it a try.

Many thanks!

20 Feb 2007, 2:40 AM
#4
millo_magno avatar

millo_magno

New Zenner

Join Date:
Nov 2006
Posts:
25
Plugin Contributions:
0

Re: Finding out what top level category a product belongs to?

Hi,

That didn't work.

It only works when there is the cPath value available in the url however when I go into the shopping cart for example. The value is no longer available to access and hence use for running conditional statements.

:-(

20 Feb 2007, 6:39 AM
#5
gjh42 avatar

gjh42

Black Belt

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

Re: Finding out what top level category a product belongs to?

If you think about it, the shopping cart page for example can't belong to an individual product or category. What if there are two products in the cart? What if you get to the shopping cart page from the main page or the shipping & returns page?

Perhaps what you need to do is grab the category id on each product page and save it in a global tracking variable if it is non-null, so a non-product page can "remember" what the last product category was.