How to show sub menus separately with categories
7 posts by 2 authors in: Forums > CMS Builder
Last Post: March 12, 2009 (RSS)
By chassa2556 - March 10, 2009 - edited: March 11, 2009
I've followed this and am getting to the first level of navigation using your code. Here is my header:
list($categoryRecords, $selectedCategory) = getCategories(array(
'tableName' => 'category',
'selectedCategoryNum' => '', // defaults to getNumberFromEndOfUrl()
'categoryFormat' => 'showall', // showall, onelevel, twolevel
));
And here is my viewer code:
<ul>
<?php foreach ($categoryRecords as $categoryRecord): ?>
<?php echo $categoryRecord['_listItemStart'] ?>
<?php if ($categoryRecord['_isSelected']): ?>
<b><a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a></b>
<?php else: ?>
<a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
<?php endif; ?>
<?php echo $categoryRecord['_listItemEnd'] ?>
<?php endforeach; ?>
<![endif]-->
</ul>
</li>
</ul>
</div>
<div id ="subCat">sub categories go here</div>
My question is how can I make the subcategories go into the div (called subCat see code above) below the parent. So when I click on News on the uppermost div News 1 | News 2 | News 3 appears on the div below??
Re: [chassa2556] Multi-level Category Functions
By Dave - March 10, 2009
Can you post some mockup html that shows what you want it to generate? How many levels deep with the menu be?
Thanks!
interactivetools.com
Re: [Dave] Multi-level Category Functions
By chassa2556 - March 10, 2009
Re: [chassa2556] Multi-level Category Functions
By chassa2556 - March 10, 2009
Re: [chassa2556] Multi-level Category Functions
By Dave - March 11, 2009
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!
interactivetools.com
Re: [Dave] Multi-level Category Functions
By chassa2556 - March 12, 2009
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
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.
interactivetools.com