Re: [chassa2556] Multi-level Category Functions
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