Show Only Subcategories on Sidebar v1.5.1.3 [SOLVED]
38 posts
• Page 1 of 2 • 1, 2
Show Only Subcategories on Sidebar v1.5.1.3 [SOLVED]
Hi,
I am having a hard time with this and have searched other posts but they didnt pertain to v1.5.1.3.
Im running v1.5.1.3 and need some menu and sidebar configuration.
When people go to the website and click on the horizontal menu bar, the subcategories will appear on the left-sidebar.
Example:
(Horizontal Sidebar)
CATEGORY ONE--CATEGORY TWO--CATEGORY THREE--CATEGORY FOUR--CATEGORY FIVE
(LEFT SIDE BAR)
--------------------------
CATEGORY ONE
-Subcategory
-Subcategory
-Subcategory
--------------------------
I only need one category to show when clicked
--------------------------
I will greatly appreciate your help...
I am having a hard time with this and have searched other posts but they didnt pertain to v1.5.1.3.
Im running v1.5.1.3 and need some menu and sidebar configuration.
When people go to the website and click on the horizontal menu bar, the subcategories will appear on the left-sidebar.
Example:
(Horizontal Sidebar)
CATEGORY ONE--CATEGORY TWO--CATEGORY THREE--CATEGORY FOUR--CATEGORY FIVE
(LEFT SIDE BAR)
--------------------------
CATEGORY ONE
-Subcategory
-Subcategory
-Subcategory
--------------------------
I only need one category to show when clicked
--------------------------
I will greatly appreciate your help...

Last edited by opencartnoobie2011 on Tue Dec 20, 2011 6:00 pm, edited 1 time in total.
- opencartnoobie2011
- Posts: 14
- Joined: Sun Dec 18, 2011 5:54 pm
Re: Show Only Subcategories on Sidebar v1.5.1.3
I really need your help guys...
- opencartnoobie2011
- Posts: 14
- Joined: Sun Dec 18, 2011 5:54 pm
Re: Show Only Subcategories on Sidebar v1.5.1.3
In catalog/view/theme/<your_template_name>/template/module/category.tpl file,
find this portion:
replace with:
This should work as expected.
find this portion:
- Code: Select all
<ul>
<?php foreach ($category['children'] as $child) { ?>
<li>
<?php if ($child['category_id'] == $child_id) { ?>
<a href="<?php echo $child['href']; ?>" class="active"> - <?php echo $child['name']; ?></a>
<?php } else { ?>
<a href="<?php echo $child['href']; ?>"> - <?php echo $child['name']; ?></a>
<?php } ?>
</li>
<?php } ?>
</ul>
replace with:
- Code: Select all
<ul>
<?php $i = 0; ?>
<?php foreach ($category['children'] as $child) { ?>
<li>
<?php if ($child['category_id'] == $child_id && $i == 0) { ?>
<a href="<?php echo $child['href']; ?>" class="active"> - <?php echo $child['name']; ?></a>
<?php } elseif ($i == 0) { ?>
<a href="<?php echo $child['href']; ?>"> - <?php echo $child['name']; ?></a>
<?php } ?>
</li>
<?php $i++; ?>
<?php } ?>
</ul>
This should work as expected.
Regards,
Straightlight
Straightlight
- straightlight
- Posts: 1911
- Joined: Mon Nov 14, 2011 3:38 pm
- Location: Canada, ON
Re: Show Only Subcategories on Sidebar v1.5.1.3
Hi Straightlight,
Thank you for your work!!
I have changed the coding accordingly but the sidebar did not conform.
I cleaned out my cache and stored settings and checked it on a couple browsers, but the sidebar still remained the same.
Help please :-/
Thank you for your work!!
I have changed the coding accordingly but the sidebar did not conform.
I cleaned out my cache and stored settings and checked it on a couple browsers, but the sidebar still remained the same.
Help please :-/
Last edited by opencartnoobie2011 on Mon Dec 19, 2011 7:58 pm, edited 1 time in total.
- opencartnoobie2011
- Posts: 14
- Joined: Sun Dec 18, 2011 5:54 pm
Re: Show Only Subcategories on Sidebar v1.5.1.3
I can't reproduce this with default template. When I click on one category from the sidebar, it only shows the first sub-category as you wanted ...
Regards,
Straightlight
Straightlight
- straightlight
- Posts: 1911
- Joined: Mon Nov 14, 2011 3:38 pm
- Location: Canada, ON
Re: Show Only Subcategories on Sidebar v1.5.1.3
Oh i see...
I am using the default template...that explains why.
Is there anything that we can do pertaining to the default template?
I am using the default template...that explains why.
Is there anything that we can do pertaining to the default template?
- opencartnoobie2011
- Posts: 14
- Joined: Sun Dec 18, 2011 5:54 pm
Re: Show Only Subcategories on Sidebar v1.5.1.3
From any templates you imply this code, it should work accordingly.
Regards,
Straightlight
Straightlight
- straightlight
- Posts: 1911
- Joined: Mon Nov 14, 2011 3:38 pm
- Location: Canada, ON
Re: Show Only Subcategories on Sidebar v1.5.1.3
I tried it again and it still remained. I have uploaded a screen shot of the categories.

I only need "Body" to be visible.
Example:

Once the user clicks on another category, only that one will be visible as well, but without the other categories visible.
I hope this helps a bit.
I am so sorry If I miss-explained in the beginning.

I only need "Body" to be visible.
Example:

Once the user clicks on another category, only that one will be visible as well, but without the other categories visible.
I hope this helps a bit.
I am so sorry If I miss-explained in the beginning.
- opencartnoobie2011
- Posts: 14
- Joined: Sun Dec 18, 2011 5:54 pm
Re: Show Only Subcategories on Sidebar v1.5.1.3
You could of been clearer stating this was about the counter of the result and not the result itself from the sub-categories.
In catalog/controller/module/category.php file,
find:
replace with:
In catalog/controller/module/category.php file,
find:
- Code: Select all
foreach ($categories as $category) {
$children_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
$i = 0;
foreach ($children as $child) {
if ($i == 0) {
$data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$children_data[] = array(
'category_id' => $child['category_id'],
'name' => $child['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
$i++;
}
$data = array(
'filter_category_id' => $category['category_id'],
'filter_sub_category' => true
);
$product_total = $this->model_catalog_product->getTotalProducts($data);
$this->data['categories'][] = array(
'category_id' => $category['category_id'],
'name' => $category['name'] . ' (' . $product_total . ')',
'children' => $children_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
replace with:
- Code: Select all
foreach ($categories as $category) {
if (((int)$this->data['category_id'] == (int)$category['category_id'])) {
$children_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
$i = 0;
foreach ($children as $child) {
if ($i == 0 && (int)$this->data['category_id'] == (int)$child['category_id']) {
$data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$children_data[] = array(
'category_id' => $child['category_id'],
'name' => $child['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
$i++;
}
$data = array(
'filter_category_id' => $category['category_id'],
'filter_sub_category' => true
);
$product_total = $this->model_catalog_product->getTotalProducts($data);
$this->data['categories'][] = array(
'category_id' => $category['category_id'],
'name' => $category['name'],
'children' => $children_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
break;
} else {
$children_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
$i = 0;
foreach ($children as $child) {
$data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$children_data[] = array(
'category_id' => $child['category_id'],
'name' => $child['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
$i++;
}
$data = array(
'filter_category_id' => $category['category_id'],
'filter_sub_category' => true
);
$product_total = $this->model_catalog_product->getTotalProducts($data);
$this->data['categories'][] = array(
'category_id' => $category['category_id'],
'name' => $category['name'],
'children' => $children_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
}
Last edited by straightlight on Tue Dec 20, 2011 12:24 am, edited 4 times in total.
Regards,
Straightlight
Straightlight
- straightlight
- Posts: 1911
- Joined: Mon Nov 14, 2011 3:38 pm
- Location: Canada, ON
Re: Show Only Subcategories on Sidebar v1.5.1.3
Hey there,
sorry about that...didnt mean to confuse you.
I am working on v1.5.1.3 of open cart and didnt see the coding you wanted me to find.
Here is my original coding...
sorry about that...didnt mean to confuse you.
I am working on v1.5.1.3 of open cart and didnt see the coding you wanted me to find.
Here is my original coding...
- Code: Select all
<div class="box">
<div class="box-heading"><?php echo $heading_title; ?></div>
<div class="box-content">
<div class="box-category">
<ul>
<?php foreach ($categories as $category) { ?>
<li>
<?php if ($category['category_id'] == $category_id) { ?>
<a href="<?php echo $category['href']; ?>" class="active"><?php echo $category['name']; ?></a>
<?php } else { ?>
<a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
<?php } ?>
<?php if ($category['children']) { ?>
<ul>
<?php foreach ($category['children'] as $child) { ?>
<li>
<?php if ($child['category_id'] == $child_id) { ?>
<a href="<?php echo $child['href']; ?>" class="active"> - <?php echo $child['name']; ?></a>
<?php } else { ?>
<a href="<?php echo $child['href']; ?>"> - <?php echo $child['name']; ?></a>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
</li>
<?php } ?>
</ul>
</div>
</div>
</div>
- opencartnoobie2011
- Posts: 14
- Joined: Sun Dec 18, 2011 5:54 pm
Re: Show Only Subcategories on Sidebar v1.5.1.3
Compare yours with mine from the location I stated above and it should work just fine. 

Regards,
Straightlight
Straightlight
- straightlight
- Posts: 1911
- Joined: Mon Nov 14, 2011 3:38 pm
- Location: Canada, ON
Re: Show Only Subcategories on Sidebar v1.5.1.3
Thanks,
I located the Category.tpl file in the module folder but the coding you asked me to find doesn't match with the coding that I have. I have the default Category.tpl file.
I located the Category.tpl file in the module folder but the coding you asked me to find doesn't match with the coding that I have. I have the default Category.tpl file.
- opencartnoobie2011
- Posts: 14
- Joined: Sun Dec 18, 2011 5:54 pm
Re: Show Only Subcategories on Sidebar v1.5.1.3
The provided code is indeed from the default template of version v1.5.1.3. However, it is from the module as mentioned on the above. Make sure the module is installed from the admin's extension module.
Regards,
Straightlight
Straightlight
- straightlight
- Posts: 1911
- Joined: Mon Nov 14, 2011 3:38 pm
- Location: Canada, ON
Re: Show Only Subcategories on Sidebar v1.5.1.3
This is the code from the default Category.tpl File:
I re-downloaded the original opencart just to check if the coding the same. It comes with categories enabled in the admin section.
-------------------------------------------------
/catalog/view/theme/default/template/module/category.tpl
------------------------------------------------
<div class="box">
<div class="box-heading"><?php echo $heading_title; ?></div>
<div class="box-content">
<div class="box-category">
<ul>
<?php foreach ($categories as $category) { ?>
<li>
<?php if ($category['category_id'] == $category_id) { ?>
<a href="<?php echo $category['href']; ?>" class="active"><?php echo $category['name']; ?></a>
<?php } else { ?>
<a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
<?php } ?>
<?php if ($category['children']) { ?>
<ul>
<?php foreach ($category['children'] as $child) { ?>
<li>
<?php if ($child['category_id'] == $child_id) { ?>
<a href="<?php echo $child['href']; ?>" class="active"> - <?php echo $child['name']; ?></a>
<?php } else { ?>
<a href="<?php echo $child['href']; ?>"> - <?php echo $child['name']; ?></a>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
</li>
<?php } ?>
</ul>
</div>
</div>
</div>
I re-downloaded the original opencart just to check if the coding the same. It comes with categories enabled in the admin section.
-------------------------------------------------
/catalog/view/theme/default/template/module/category.tpl
------------------------------------------------
<div class="box">
<div class="box-heading"><?php echo $heading_title; ?></div>
<div class="box-content">
<div class="box-category">
<ul>
<?php foreach ($categories as $category) { ?>
<li>
<?php if ($category['category_id'] == $category_id) { ?>
<a href="<?php echo $category['href']; ?>" class="active"><?php echo $category['name']; ?></a>
<?php } else { ?>
<a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
<?php } ?>
<?php if ($category['children']) { ?>
<ul>
<?php foreach ($category['children'] as $child) { ?>
<li>
<?php if ($child['category_id'] == $child_id) { ?>
<a href="<?php echo $child['href']; ?>" class="active"> - <?php echo $child['name']; ?></a>
<?php } else { ?>
<a href="<?php echo $child['href']; ?>"> - <?php echo $child['name']; ?></a>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
</li>
<?php } ?>
</ul>
</div>
</div>
</div>
- opencartnoobie2011
- Posts: 14
- Joined: Sun Dec 18, 2011 5:54 pm
Re: Show Only Subcategories on Sidebar v1.5.1.3
Well, yes ... this is no different than my code above ... I don't really understand what should be resolved here ...
Regards,
Straightlight
Straightlight
- straightlight
- Posts: 1911
- Joined: Mon Nov 14, 2011 3:38 pm
- Location: Canada, ON
Re: Show Only Subcategories on Sidebar v1.5.1.3
I cannot find:
In my coding...
- Code: Select all
foreach ($children as $child) {
$data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$product_total = $this->model_catalog_product->getTotalProducts($data);
$children_data[] = array(
'category_id' => $child['category_id'],
'name' => $child['name'] . ' (' . $product_total . ')',
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
In my coding...
- Code: Select all
<div class="box">
<div class="box-heading"><?php echo $heading_title; ?></div>
<div class="box-content">
<div class="box-category">
<ul>
<?php foreach ($categories as $category) { ?>
<li>
<?php if ($category['category_id'] == $category_id) { ?>
<a href="<?php echo $category['href']; ?>" class="active"><?php echo $category['name']; ?></a>
<?php } else { ?>
<a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
<?php } ?>
<?php if ($category['children']) { ?>
<ul>
<?php foreach ($category['children'] as $child) { ?>
<li>
<?php if ($child['category_id'] == $child_id) { ?>
<a href="<?php echo $child['href']; ?>" class="active"> - <?php echo $child['name']; ?></a>
<?php } else { ?>
<a href="<?php echo $child['href']; ?>"> - <?php echo $child['name']; ?></a>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
</li>
<?php } ?>
</ul>
</div>
</div>
</div>
- opencartnoobie2011
- Posts: 14
- Joined: Sun Dec 18, 2011 5:54 pm
Re: Show Only Subcategories on Sidebar v1.5.1.3
I see. It would seem I didn't had this simple second to edit my topic once I posted it. I changed the tpl extension from extension to php. Sorry for this. That part is in the controller, not template.
Regards,
Straightlight
Straightlight
- straightlight
- Posts: 1911
- Joined: Mon Nov 14, 2011 3:38 pm
- Location: Canada, ON
Re: Show Only Subcategories on Sidebar v1.5.1.3
I found:
catalog/controller/module/category.php file and changed the coding accordingly.
It didn't get rid of the other categories

Instead what happened after applying the new code was...
The category "Body (2)" became "Body (1')" in the sidebar along with all of the main categories still intact. Like in figure 1.
catalog/controller/module/category.php file and changed the coding accordingly.
It didn't get rid of the other categories

Instead what happened after applying the new code was...
The category "Body (2)" became "Body (1')" in the sidebar along with all of the main categories still intact. Like in figure 1.
- opencartnoobie2011
- Posts: 14
- Joined: Sun Dec 18, 2011 5:54 pm
Re: Show Only Subcategories on Sidebar v1.5.1.3
If you wish to get rid of the counter entirely from catalog/controller/module/category.php file, after applying these modifications, you can
replace:
with this:
This will simply show the sub-category name without counter.
replace:
- Code: Select all
'name' => $child['name'] . ' (1)',
with this:
- Code: Select all
'name' => $child['name'],
This will simply show the sub-category name without counter.
Regards,
Straightlight
Straightlight
- straightlight
- Posts: 1911
- Joined: Mon Nov 14, 2011 3:38 pm
- Location: Canada, ON
Re: Show Only Subcategories on Sidebar v1.5.1.3
Thanks for showing me how to remove the counter.
I only want to show the "body" category when clicked.
The "hair, etc" main categories are still visible. I need them to be gone from the sidebar.
I only want to show one category and its subcategories at a time when clicked on the menu bar.
I only want to show the "body" category when clicked.
The "hair, etc" main categories are still visible. I need them to be gone from the sidebar.
I only want to show one category and its subcategories at a time when clicked on the menu bar.
- opencartnoobie2011
- Posts: 14
- Joined: Sun Dec 18, 2011 5:54 pm
38 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: digitalquill, emiku, Google [Bot], mamala, mikeltn, W3C [Validator], Yahoo [Bot] and 92 guests













