I'm running version 1.5.3.1 and am trying to make it so that I can exclude specific categories from the category sidebar. Any ideas?
Thanks in advance for any feedback!
I've looked around but haven't been able to find anything covering this. If there is already a thread and I missed it please feel free to direct me to it. Thank you!
-Andrew
Thanks in advance for any feedback!
I've looked around but haven't been able to find anything covering this. If there is already a thread and I missed it please feel free to direct me to it. Thank you!
-Andrew
All you have to do is set up a conditional in the foreach loop that lists the category_id's. You'd be using !=
Example:
In /catalog/controller/module/category.php find this code:
Make it look like this, filling in you category id's that tie to the categories you don't want to show:
Example:
In /catalog/controller/module/category.php find this code:
Code: Select all
<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>
Code: Select all
<ul>
<?php foreach ($categories as $category) { ?>
<li>
<?php if ($category['category_id'] == $category_id) { ?>
<?php if ($category['category_id'] != "23" || $category['category_id'] != "24" || $category['category_id'] != "25" || $category['category_id'] != "26"){?>
<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 } ?>
<?php } ?>
</li>
<?php } ?>
</ul>
Thanks for the reply Avvici! I tried inserting the code and it seems like it wants to work but it ends up removing all the categories and only displays the category that is selected. Almost the opposite of what I'm trying to do. There are 3 categories listed in the sidebar that I want to exclude.
if you look at this page it will give you a better idea.
http://174.132.168.188/~wwwjooni/index. ... ry&path=60
I'm trying to hide the "whats new","celebrity picks" and "lookbook" categories from the left of the page.
here is the code in the /catalog/view/theme/default/template/module/category.tpl
if you look at this page it will give you a better idea.
http://174.132.168.188/~wwwjooni/index. ... ry&path=60
I'm trying to hide the "whats new","celebrity picks" and "lookbook" categories from the left of the page.
here is the code in the /catalog/view/theme/default/template/module/category.tpl
Code: Select all
<div class="box">
<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="catheading"><?php echo $category['name']; ?></a>
<?php } else { ?>
<a href="<?php echo $category['href']; ?>" class="catheading"><?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>
Ok I have opened /catalog/controller/module/category.php and guess that the following needs adjusting:
I will play around with it and see if I can work it out.
Code: Select all
if (isset($parts[0])) {
$this->data['category_id'] = $parts[0];
} else {
$this->data['category_id'] = 0;
}
At /catalog/controller/module/category.php
Find the following lines of code
Change to the following, added some lines:
$excludecategory = array('20','25');
This is the array which exclude the category, 20 and 25 are the category id. Include the category id in the array to exclude from the sidebar
Find the following lines of code
Code: Select all
$this->data['categories'][] = array(
'category_id' => $category['category_id'],
'name' => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $total . ')' : ''),
'children' => $children_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
Code: Select all
$excludecategory = array('20','25');
if (!in_array($category['category_id'], $excludecategory)) {
$this->data['categories'][] = array(
'category_id' => $category['category_id'],
'name' => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $total . ')' : ''),
'children' => $children_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
}
This is the array which exclude the category, 20 and 25 are the category id. Include the category id in the array to exclude from the sidebar
Rupak Nepali
webocreation.com@gmail.com
http://webocreation.com
Enjoy! Tips and tricks as well as free module.
Hi Rupak,
I tried the code, but it just spits out an error: Undefined variable: category in ... line 31,
where line 31 is:
I tried the code, but it just spits out an error: Undefined variable: category in ... line 31,
where line 31 is:
Code: Select all
if (!in_array($category['category_id'], $excludecategory)) {
Code: Select all
foreach ($categories as $category) {
}
You have to remove the following
Code: Select all
$this->data['categories'][] = array(
'category_id' => $category['category_id'],
'name' => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $total . ')' : ''),
'children' => $children_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
Code: Select all
$excludecategory = array('20','25');
if (!in_array($category['category_id'], $excludecategory)) {
$this->data['categories'][] = array(
'category_id' => $category['category_id'],
'name' => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $total . ')' : ''),
'children' => $children_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
}
Rupak Nepali
webocreation.com@gmail.com
http://webocreation.com
Enjoy! Tips and tricks as well as free module.
Who is online
Users browsing this forum: Majestic-12 [Bot] and 18 guests