Sub Category Nav for Selected Section

5 posts by 2 authors in: Forums > CMS Builder
Last Post: August 23, 2010   (RSS)

Re: [aquaman] Sub Category Nav for Selected Section

By Jason - August 23, 2010

Hi Jan,

Just to make sure I understand what you're going for, you want to only display the children of the selected category. Is that right?

If so, you can try something like this:
(Note this code hasn't been tested)

<?php
// load records
list($pagesRecords, $pagesMetaData) = getCategories(array(
'tableName' => 'pages',
'selectedCategoryNum' => '', // defaults to getNumberFromEndOfUrl()
));
?>

<?php
$selectedCat="";
foreach ($pagesRecords as $record){
if($record['_isSelected']){
$selectedCat=$record['num'];
break;
}
}
?>

<?php foreach ($pagesRecords as $record): ?>

<?php if ($record['depth'] == 0) { continue; } ?>

<?php if($record['active']==1 && $record['hide']==0 && $record['parentNum']==$selectedCat): ?>
<li><a href="/<?php echo ($record['url']);?>-<?php echo ($record['num']);?>/"><?php echo htmlspecialchars($record['name']);?></a></li>
<?php endif ?>

<?php endforeach; ?>


This code will go through all your records and will find the selected category. It will then only display records who's parent category was the selected category.

Give that a try and let me know if that's doing what you're wanting.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

Re: [Jason] Sub Category Nav for Selected Section

By theclicklab - August 23, 2010

Hi Jason,

Yes, that's correct it only shows the children.

I have tested and am having a problem getting the variable "selectedCat" which is not being set.

If I hard code in "selectedCat" everything works fine.

I just can't figure out why it's not being set?

Many Thanks,
Jan

Re: [aquaman] Sub Category Nav for Selected Section

By Jason - August 23, 2010

Hi,

$selectedCat is only set if a category has been selected. We can set it to a default value if nothing has been selected if you like.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

Re: [Jason] Sub Category Nav for Selected Section

By theclicklab - August 23, 2010

Hi Jason,

Thanks for your help, your last post did the trick, I got it by changing:

<?php
$selectedCat="";
foreach ($pagesRecords as $record){
if($record['_isSelected']){
$selectedCat=$record['num'];
break;
}
}
?>


to

<?php $selectedCat=$pagesRecord['num']; ?>