Page 1 of 2
Show Only Subcategories on Sidebar v1.5.1.3 [SOLVED]
Posted: Mon Dec 19, 2011 2:16 am
by opencartnoobie2011
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...

Re: Show Only Subcategories on Sidebar v1.5.1.3
Posted: Mon Dec 19, 2011 3:19 am
by opencartnoobie2011
I really need your help guys...
Re: Show Only Subcategories on Sidebar v1.5.1.3
Posted: Mon Dec 19, 2011 4:35 am
by straightlight
In catalog/view/theme/<your_template_name>/template/module/category.tpl file,
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.
Re: Show Only Subcategories on Sidebar v1.5.1.3
Posted: Tue Dec 20, 2011 3:22 am
by opencartnoobie2011
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 :-/
Re: Show Only Subcategories on Sidebar v1.5.1.3
Posted: Tue Dec 20, 2011 3:36 am
by straightlight
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 ...
Re: Show Only Subcategories on Sidebar v1.5.1.3
Posted: Tue Dec 20, 2011 3:58 am
by opencartnoobie2011
Oh i see...
I am using the default template...that explains why.
Is there anything that we can do pertaining to the default template?
Re: Show Only Subcategories on Sidebar v1.5.1.3
Posted: Tue Dec 20, 2011 4:00 am
by straightlight
From any templates you imply this code, it should work accordingly.
Re: Show Only Subcategories on Sidebar v1.5.1.3
Posted: Tue Dec 20, 2011 5:18 am
by opencartnoobie2011
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.
Re: Show Only Subcategories on Sidebar v1.5.1.3
Posted: Tue Dec 20, 2011 5:25 am
by straightlight
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:
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'])
);
}
}
Re: Show Only Subcategories on Sidebar v1.5.1.3
Posted: Tue Dec 20, 2011 5:35 am
by opencartnoobie2011
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...
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>
Re: Show Only Subcategories on Sidebar v1.5.1.3
Posted: Tue Dec 20, 2011 5:39 am
by straightlight
Compare yours with mine from the location I stated above and it should work just fine.

Re: Show Only Subcategories on Sidebar v1.5.1.3
Posted: Tue Dec 20, 2011 5:51 am
by opencartnoobie2011
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.
Re: Show Only Subcategories on Sidebar v1.5.1.3
Posted: Tue Dec 20, 2011 5:55 am
by straightlight
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.
Re: Show Only Subcategories on Sidebar v1.5.1.3
Posted: Tue Dec 20, 2011 6:09 am
by opencartnoobie2011
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>
Re: Show Only Subcategories on Sidebar v1.5.1.3
Posted: Tue Dec 20, 2011 6:33 am
by straightlight
Well, yes ... this is no different than my code above ... I don't really understand what should be resolved here ...
Re: Show Only Subcategories on Sidebar v1.5.1.3
Posted: Tue Dec 20, 2011 6:39 am
by opencartnoobie2011
I cannot find:
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>
Re: Show Only Subcategories on Sidebar v1.5.1.3
Posted: Tue Dec 20, 2011 6:46 am
by straightlight
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.
Re: Show Only Subcategories on Sidebar v1.5.1.3
Posted: Tue Dec 20, 2011 7:14 am
by opencartnoobie2011
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.
Re: Show Only Subcategories on Sidebar v1.5.1.3
Posted: Tue Dec 20, 2011 7:18 am
by straightlight
If you wish to get rid of the counter entirely from catalog/controller/module/category.php file, after applying these modifications, you can
replace:
Code: Select all
'name' => $child['name'] . ' (1)',
with this:
This will simply show the sub-category name without counter.
Re: Show Only Subcategories on Sidebar v1.5.1.3
Posted: Tue Dec 20, 2011 7:30 am
by opencartnoobie2011
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.