Post by jvesanto » Sat Jun 18, 2011 9:36 pm

I'm in the process of moving an existing site over to OpenCart 1.5, and as this site has a significant number of sub-categories, the single column dropdown menu wasn't really working for me. In case anybody else is in a similar position, this quick mod will allow you to show the sub-categories in multiple columns, rather than just one single one.

EDIT: /catalog/view/theme/default/template/common/header.tpl

FIND:

Code: Select all

      <div>
        <?php for ($i = 0; $i < count($category['children']);) { ?>
        <ul>
          <?php $j = $i + ceil(count($category['children']) / $category['column']); ?>
          <?php for (; $i < $j; $i++) { ?>
          <?php if (isset($category['children'][$i])) { ?>
          <li><a href="<?php echo $category['children'][$i]['href']; ?>"><?php echo $category['children'][$i]['name']; ?></a></li>
          <?php } ?>
          <?php } ?>
        </ul>
        <?php } ?>
      </div>
REPLACE:

Code: Select all

      <div>
        <?php for ($i = 0; $i < count($category['children']);) { ?>       
        <?php if (count($category['children']) <= 10) { ?>
        <ul>
          <?php $j = $i + ceil(count($category['children']) / $category['column']); ?>
          <?php for (; $i < $j; $i++) { ?>
          <?php if (isset($category['children'][$i])) { ?>
          <li><a href="<?php echo $category['children'][$i]['href']; ?>"><?php echo $category['children'][$i]['name']; ?></a></li>
          <?php } ?>
          <?php } ?>
        </ul>
        <?php } else { ?>        
        <ul>
          <?php $j = $i + ceil(count($category['children']) / 4); ?>
          <?php for (; $i < $j; $i++) { ?>
          <?php if (isset($category['children'][$i])) { ?>
          <li><a href="<?php echo $category['children'][$i]['href']; ?>"><?php echo $category['children'][$i]['name']; ?></a></li>
          <?php } ?>
          <?php } ?>
        </ul>
        <?php } ?>
        <?php } ?>
      </div>
The end result should look something like this:

Image

The code above will display any category with more than 10 sub-categories in 4 columns. The number of sub-categories required before it displays in columns can be modified by replacing the number 10 in:

Code: Select all

<?php if (count($category['children']) <= 10) { ?>
The number of columns can be modified by replacing the number 4 in:

Code: Select all

<?php $j = $i + ceil(count($category['children']) / 4); ?>
Hope this is useful to someone!

Newbie

Posts

Joined
Sat Jun 18, 2011 9:07 pm

Post by Xsecrets » Sat Jun 18, 2011 10:34 pm

you did realize this is built right into the system without any mods right? All you have to do is on the main category set how many columns you want it to use. For an example check out the test category on the demo.

OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter


Guru Member

Posts

Joined
Sun Oct 25, 2009 3:51 am
Location - FL US

Post by jvesanto » Sat Jun 18, 2011 10:46 pm

I'm not sure how I missed that! How silly of me. Oh well, such is life!

Newbie

Posts

Joined
Sat Jun 18, 2011 9:07 pm

Post by Alexx84 » Thu Jan 16, 2014 2:15 am

Hy, I am on OpenCart 1.5.6.I want to put one of my categories in 3 colums, cause it has 25 sub-categories... Is this option available somewhere within interface cause I cant find it? Any help would be much appreciated...

Newbie

Posts

Joined
Thu Jan 16, 2014 2:12 am

Post by bijolianabhi » Sun Mar 22, 2015 6:52 pm

@alexx84: All you have to do is on the main category set how many columns you want it to use. You can set there number of columns that you want to use for that category.

Newbie

Posts

Joined
Sun Mar 22, 2015 6:51 pm
Who is online

Users browsing this forum: No registered users and 6 guests