1

I have an URL from which I would like to get the categories. I have this: /hats/trucker-hats/hat1.html/ which is a product detail page.

I need to retrieve the categories, which are "hats" and "trucker-hats". I tried using $product->getCategoryIds() and looked through the IDs, the categories are there, but never at the same index, is there a way to retrieve these?

Thanks

2
  • what do you mean by "never at the same index" ?
    – Alex
    Commented Jul 24, 2014 at 8:32
  • When I look at the array of category ids from page to page, I find the same ids, but they don't always have the same index in the array Commented Jul 24, 2014 at 14:13

2 Answers 2

1

You can get categories from the breadcrumbs

$title = array();
$path  = Mage::helper('catalog')->getBreadcrumbPath();
foreach ($path as $breadcrumb) {
    $title[] = $breadcrumb['label'];
}
0

To get a consistent ordering you can use asort().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.