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!
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!
$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 Code:
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
...
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!
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.
:-(
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.
Bookmarks