Sub Category Nav for Selected Section

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

By theclicklab - August 20, 2010

Hi there, I'm trying to get a subnav showing for the following conditions:

-Page is Top Level (no parent)
-Page has children

My problem is that my code is showing all second level list items for the whole site no matter what page I am on - not those items under the selected top level page only.

Here is the code Im using:

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

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

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

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

<?php endforeach; ?>


Any tips?

Many Thanks, Jan

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: [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']; ?>