Menu links

3 posts by 2 authors in: Forums > CMS Builder
Last Post: September 10, 2015   (RSS)

Hi Guys.

I've got a category section building the structure of my site, with 1st level records creating the pages, then 2nd level records creating sections within the parent page.

I'm building a site map with

<?php
// load records from 'pages'
list($pagesRecords, $selectedPages) = getCategories(array(
'tableName' => 'pages', //
'categoryFormat' => 'showall', // showall, onelevel, twolevel, breadcrumb
'defaultCategory' => '', // Enter 'first', a category number, or leave blank '' for none

// advanced options (you can safely ignore these)
'rootCategoryNum' => '', // Only categories _below_ this one will be shown (defaults to blank or 0 for all)
'ulAttributes' => '', // add html attributes to <ul> tags, eg: 'class="menuUL"' would output <ul class="menuUL">
'selectedCategoryNum' => '', // this record number is returned as the "selected category", defaults to getLastNumberInUrl()
'ulAttributesCallback' => '', // ADVANCED: custom function to return ul attributes, eg: 'myUlAttr' and function myUlAttr($category) { return "id='ul_uniqueId_{$category['num']}'"; }
'liAttributesCallback' => '', // ADVANCED: custom function to return li attributes, eg: 'myLiAttr' and function myLiAttr($category) { return "id='li_uniqueId_{$category['num']}'"; }
'loadCreatedBy' => false, // loads createdBy.* fields for user who created category record (false is faster)
'loadUploads' => true, // loads upload fields, eg: $category['photos'] gets defined with array of uploads (false is faster)
'ignoreHidden' => false, // false = hide records with 'hidden' flag set, true = ignore status of hidden flag when loading records
'debugSql' => false, // display the MySQL query being used to load records (for debugging)
));

?>
<ul class="footerList">
<?php foreach ($pagesRecords as $categoryRecord): ?>

<?php echo $categoryRecord['_listItemStart'] ?>

<?php if ($categoryRecord['_hasChild']): ?>
<a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
<?php else: ?>
<a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
<?php endif; ?>

<?php echo $categoryRecord['_listItemEnd'] ?>

<?php endforeach; ?>
</ul>

This displays fine, the "parent" link (blue) goes to the page such as /page.php?About-1.  However the children (red) go to /page.php?About-The-NTA-7 and I need them to go to /page.php?About-1#section1 where the id is created by id="section<?php echo htmlencode($record['num']) ?>">

Is that possible?

Cheers,

Tim (toledoh.com.au)

Hey Tim,

I think something like this should work:

<ul class="footerList">
  <?php foreach ($pagesRecords as $categoryRecord): ?>

    <?php echo $categoryRecord['_listItemStart'] ?>

    <?php if ($categoryRecord['_hasChild']): ?>
    <a href="<?php echo $categoryRecord['_link'] ?>"><?php echo htmlEncode($categoryRecord['name']); ?></a>
    <?php $parentLink = $categoryRecord['_link']; ?> 
    <?php else: ?>
    <a href="<?php echo $parentLink ?>#section<?php echo $categoryRecord['num']; ?>"><?php echo htmlEncode($categoryRecord['name']); ?></a>
    <?php endif; ?>

    <?php echo $categoryRecord['_listItemEnd'] ?>

  <?php endforeach; ?>
</ul>

So if we're dealing with a top level page, we set its URL to the variable parent link. Then if we're dealing with a second level page, we use the $parentLink variable to use the parent page URL.

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com