Page 1 of 1

[MOD][1.5] Multiple columns in dropdown menu

Posted: Sat Jun 18, 2011 9:36 pm
by jvesanto
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!

Re: [MOD][1.5] Multiple columns in dropdown menu

Posted: Sat Jun 18, 2011 10:34 pm
by Xsecrets
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.

Re: [MOD][1.5] Multiple columns in dropdown menu

Posted: Sat Jun 18, 2011 10:46 pm
by jvesanto
I'm not sure how I missed that! How silly of me. Oh well, such is life!

Re: [MOD][1.5] Multiple columns in dropdown menu

Posted: Thu Jan 16, 2014 2:15 am
by Alexx84
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...

Re: [MOD][1.5] Multiple columns in dropdown menu

Posted: Sun Mar 22, 2015 6:52 pm
by bijolianabhi
@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.