deeve deeve - 1 year ago 224
PHP Question

opencart - get parent category name/id on a sub-category page? New

Okay, I've been asked to repost this as a moderator deemed it to be a 'new' question to this thread: opencart - get parent category name/id on a sub-category page

I believe it to be a valid question related to that title so have posted it here in compliance. Any help would be very much appreciated:

Being a newbie to this concept I'm struggling to interpret the logic within the original thread [above] when applying it to my particular scenario; I'm trying to display the currently displayed category's parent category name. In category.php I've included the line

$categories = explode('_', $this->request->get['path']);
but am having difficulty in displaying the parent category name. I'm unclear as to the correct variable name to use in category.tpl to display this. Could someone please advise? Thanks.

Answer Source

Find (catalog/controller/product/category.php) around line 95

if ($category_info) {

Add inside

if($category_info['parent_id'] != 0){
 $this->data['parent_cat_info'] = $this->model_catalog_category->getCategory($category_info['parent_id']);

now in template file (/catalog/view/theme/default/template/product/category.tpl) you can access the properties of array $parent_cat_info e.g for category name echo $parent_cat_info['name']

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download