How to show sub menus separately with categories

7 posts by 2 authors in: Forums > CMS Builder
Last Post: March 12, 2009   (RSS)

Re: [chassa2556] Multi-level Category Functions

By Dave - March 10, 2009

Hi Charles,

Can you post some mockup html that shows what you want it to generate? How many levels deep with the menu be?

Thanks!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Multi-level Category Functions

http://www.mercerdesign.biz/cms/categoryList.php?News-1

But the sub categories would go underneath the categories eg News | Products | Contact would be on the top row and in a row underneath (when news is selected) would be News 1 | News 2 | News 3.

Re: [chassa2556] Multi-level Category Functions

It would just be two levels deep .

Another question could I change the design so the News category would have a slightly different design layout to say products?

Re: [chassa2556] Multi-level Category Functions

By Dave - March 11, 2009

Hi Charles,

We'll have tackle one problem at a time, so lets start with splitting up the menus.

We've been adding some features to the next version to make this easier. I've updated your /cmsAdmin/lib/viewer_functions.php as follows:

- Search for _isSelected
- Replace that line (around line 558) with this: (this will be in v1.28)
list($selectedRootNum) = preg_split('/:/', @$selectedCategory['lineage'],-1,PREG_SPLIT_NO_EMPTY); // root num of selected records branch
$category['_isSelected'] = (int) ($category['num'] == $options['selectedCategoryNum']);
$category['_isAncestorSelected'] = $selectedCategory && preg_match("/:{$selectedCategory['num']}/", $category['lineage']) && !$category['_isSelected'];
$category['_isDescendantSelected'] = $selectedCategory && preg_match("/:{$category['num']}:/", $selectedCategory['lineage']) && !$category['_isSelected'];
$category['_isSelectedBranch'] = $selectedCategory && preg_match("/:{$selectedRootNum}:/", $category['lineage']);


Next, I've updated your /cms/categoryList.php file as follows:
<?php foreach ($categoryRecords as $categoryRecord): ?>
<?php if ($categoryRecord['depth'] != 0) { continue; } ?>

<?php if ($categoryRecord['_isSelectedBranch']): ?>
<li><b><a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a></b></li>
<?php else: ?>
<li><a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a></li>
<?php endif; ?>

<?php endforeach; ?>


Which basically means don't show any items that aren't at depth 0 which means root items. And I've added this block to show sublevel items:
<div id ="subCat">
<?php foreach ($categoryRecords as $categoryRecord): ?>
<?php if ($categoryRecord['depth'] == 0) { continue; } ?>
<?php if (!$categoryRecord['_isSelectedBranch']) { continue; } ?>


<?php if ($categoryRecord['_isSelected']): ?>
<li><b><a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a></b></li>
<?php else: ?>
<li><a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a></li>
<?php endif; ?>

<?php endforeach; ?>
</div>


Which means, skip root items, and only show menu items in selected branch (meaning root parent is selected).

Here's a working link: http://www.mercerdesign.biz/cms/categoryList.php?Products-2

You'll notice the sub menu needs to be styled but I'll leave that to you.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Multi-level Category Functions

Dave - you're a gem thanks so much for your time and effort on this its working fine now.

One last thing on this which would make it really powerful tool - could I change the design layout for say Products so the layout would be different in nature than News?

Re: [chassa2556] Multi-level Category Functions

By Dave - March 12, 2009

Hi Charles,

Yes you can, the first step would be to create a mockup of how you want those two sections to look.

Let me know when you get that far and we can work on the next step.
Dave Edis - Senior Developer
interactivetools.com