Displaying category levels in navigation

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

By Toledoh - May 25, 2013

Hi Guys,

I'm pretty close, but just can't get the last of this working... can you help?

I've trying to display 1st level navigation in the #mainNav, and 2nd Level Navigation in the #sideNav, which is generally working fine - however if I select at iten in the #mainNav that has children, it displays the children in the #mainNav as well as in the #sideNav.

Refer: http://freestylepools.com.au/web2013/index.php

  // load detail record from 'navigation'
  list($navigationRecords, $navigationMetaData) = getRecords(array(
    'tableName'   => 'navigation',
    'where'       => whereRecordNumberInUrl(1), // If no record # is specified then latest record is shown
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $detailRecord = @$navigationRecords[0]; // get first record
  if (!$detailRecord) { dieWith404("Record not found!"); } // show error message if no record found

  // load level 1 menu (note: program calls this depth and starts counting at 0)
  $SELECTED_MENU_NUM = coalesce(@$SELECTED_MENU_NUM, getLastNumberInUrl());
  list($level1MenuRecords, $selectedMenuRecord) = getCategories(array(
    'tableName'             => 'navigation',           // REQUIRED
    //'rootCategoryNum'       => '0',                 // Only categories _below_ this one will be shown (defaults to 0 for all)
    'defaultCategory'       => '',               // Enter 'first', a category number, or leave blank '' for none
    'selectedCategoryNum'   => $SELECTED_MENU_NUM,    // defaults to getLastNumberInUrl()
    'categoryFormat'        => 'onelevel',            // showall, onelevel, twolevel, breadcrumb
  ));
  if (!$SELECTED_MENU_NUM) { $SELECTED_MENU_NUM = $selectedMenuRecord['num']; }

  // load level 2-3 menu
  $level2MenuRecords = array();
  if ($selectedMenuRecord) {
    list(,$rootNumSelected) = explode(":", $selectedMenuRecord['lineage']); // lineage shows parent nums, eg, 3rd level record 33 might show. :1:12:33:
    list($level2MenuRecords,) = getCategories(array(
      'tableName'             => 'navigation',          // REQUIRED
      'rootCategoryNum'       => $rootNumSelected,      // Only categories _below_ this one will be shown (defaults to 0 for all)
      //'defaultCategory'       => 'first',             // Enter 'first', a category number, or leave blank '' for none
      //'selectedCategoryNum'   => '',                  // defaults to getLastNumberInUrl()
      'categoryFormat'        => 'onelevel',           // showall, onelevel, twolevel, breadcrumb
    ));
  }

I've got the following;

<ul id="sideNav">
<?php foreach ($level2MenuRecords as $listRecord): ?>
  <?php $isSelected = ($listRecord['num'] == $detailRecord['num']); ?>
              <li><a href="<?php echo htmlencode($listRecord['_link']) ?>" class="<?php if ($isSelected) { print "current"; } ?>" ><?php echo htmlencode($listRecord['title']) ?></a></li>
<?php endforeach ?>
 </ul>

<nav class="row">
    <ul id="mainNav" class="content">
    <?php foreach ($level1MenuRecords as $listRecord): ?>
      <?php $isSelected = ($listRecord['num'] == $detailRecord['num']); ?>
      <li><a href="<?php echo htmlencode($listRecord['_link']) ?>" class="<?php if ($isSelected) { print "current"; } ?>"><?php echo htmlencode($listRecord['title']) ?></a></li>
    <?php endforeach ?>

    </ul>
</nav>

Cheers,

Tim (toledoh.com.au)