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

  • what do you mean by "never at the same index" ? – Alex Jul 24 '14 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 – Jonathan Pellerin Jul 24 '14 at 14:13
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, privacy policy and cookie policy

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