How to generate nav menu for only particular part of a Category menu tree branch?

2 posts by 2 authors in: Forums > CMS Builder
Last Post: June 27, 2012   (RSS)

Re: [davidcmsb] How to generate nav menu for only particular part of a Category menu tree branch?

By Jason - June 27, 2012

Hi David,

An easier way to do this would be to use getCategories to return all the children of the selected category. When there is a record number at the end of your url, getCategories will attempt to return $selectedRecord, which is the record that matches the number in the url. With this, we can perform a second getCategories call like this:

$childCategories = array();

if ($selectedCategory) {
list($childCategories, ) = getCategories(array(
'tableName' => 'category',
'rootCategoryNum' => intval($selectedCategory['num']),
));
}


You can then output it like this:

<?php if ($selectedCategory): ?>
<ul>
<li><?php echo $selectedCategory['name'];?></li>
<ul>
<?php endif ?>

<?php foreach ($childCategories as $category): ?>
<?php echo $category['_listItemStart'];?>
<?php echo $category['name']."-".$category['num'];?>
<?php echo $category['_listItemEnd'];?>
<?php endforeach ?>

<?php if ($selectedCategory): ?>
</ul>
</ul>
<?php endif ?>


Hope this helps get you started
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/