Post by agraves912 » Wed Oct 03, 2012 4:15 am

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

Newbie

Posts

Joined
Wed Oct 03, 2012 3:22 am

Post by Avvici » Thu Oct 04, 2012 10:00 am

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:

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>
Make it look like this, filling in you category id's that tie to the categories you don't want to show:

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>

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by agraves912 » Thu Oct 04, 2012 5:54 pm

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

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>

Newbie

Posts

Joined
Wed Oct 03, 2012 3:22 am

Post by Avvici » Thu Oct 04, 2012 11:02 pm

PM me. I can fix this for you outside of the forum.

User avatar
Expert Member

Posts

Joined
Tue Apr 05, 2011 12:09 pm
Location - Asheville, NC

Post by Wardy_118 » Fri Dec 07, 2012 10:52 pm

Hi,

Does anyone know how to go about doing the above for version 1.5.1.3.1 ?

Thanks

New member

Posts

Joined
Tue Apr 13, 2010 5:50 pm

Post by Wardy_118 » Sat Dec 08, 2012 3:16 am

Ok I have opened /catalog/controller/module/category.php and guess that the following needs adjusting:

Code: Select all

if (isset($parts[0])) {
			$this->data['category_id'] = $parts[0];
		} else {
			$this->data['category_id'] = 0;
		}
I will play around with it and see if I can work it out.

New member

Posts

Joined
Tue Apr 13, 2010 5:50 pm

Post by rupaknepali » Sat Dec 08, 2012 5:33 am

At /catalog/controller/module/category.php
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'])
					);	
				}
Change to the following, added some lines:

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'])
					);	
				}
		}
$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

Rupak Nepali
webocreation.com@gmail.com
http://webocreation.com
Enjoy! Tips and tricks as well as free module.


Active Member

Posts

Joined
Mon Apr 25, 2011 7:04 pm

Post by SupraTwinTurbo » Sat Dec 08, 2012 11:51 am

Hi Rupak,

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)) {

User avatar
New member

Posts

Joined
Thu Mar 24, 2011 12:43 pm
Location - NYC, NY USA

Post by rupaknepali » Sun Dec 09, 2012 1:22 pm

Code: Select all

foreach ($categories as $category) {
}
the code must be before the closing tags of above foreach

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'])
					);	
and add the following code

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.


Active Member

Posts

Joined
Mon Apr 25, 2011 7:04 pm

Post by Wardy_118 » Mon Dec 10, 2012 6:04 pm

Thank you rupaknepali :)

That code works like a charm...

Thanks again.

New member

Posts

Joined
Tue Apr 13, 2010 5:50 pm
Who is online

Users browsing this forum: Majestic-12 [Bot] and 26 guests