Reputation: 4044
I want to display the category title on the products details page. I could do it by displaying the last breadcrumb (which would be the category), but if I do that it won't show up if I access the product from the "specials" page (since it doesn't display the categories in the breadcrumb - just "Home > Product2").
How would I go about getting the category ID so I can then pull the title from that?
Thanks!
Upvotes: 4
Views: 14312
Reputation: 4044
I found the solution:
In /catalog/controller/product/product.php
somewhere after line 129 add:
$categories = $this->model_catalog_product->getCategories($product_id);
if ($categories)
$categories_info = $this->model_catalog_category->getCategory($categories[0]['category_id']);
$this->data['category_title'] = $categories_info['name'];
This will get the product's first category title (since a product may be in more than one category).
After that, in the product.tpl echo $category_title;
Upvotes: 7