Navigation List Issue

7 posts by 3 authors in: Forums > CMS Builder
Last Post: February 4, 2014   (RSS)

By rconring - February 3, 2014 - edited: February 3, 2014

Make sure the viewer is using  getCategories(array( NOT getRecords(array( Then just place _listItemStart and _listItemEnd at the top and bottom of the foreach loop.  It will place the list tags in the appropriate places ... you do not have to track parent/child records.

Here is some info on it:  http://www.interactivetools.com/forum/forum-posts.php?postNum=2192758#post2192758

Also FYI, if you use the special fieldname "hidden" instead of "hide" you do not have to manually filter out hidden records.  The viewer omits them.

<ul class="top">
<?php foreach ($destinationsRecords as $record): ?>
  <?php echo $record['_listItemStart']; ?>
  <?php if($record['active']==1 && $record['hide']==0): ?>
    <a href="/<?php echo $record['_link'];?>"><?php echo htmlspecialchars($record['name']);?></a>  
  <?php endif ?>
<?php echo $record['_listItemEnd']; ?>
<?php endforeach ?>
</ul>

Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987

Hi,

Ron's suggestion seems to be on the money. Have you had any luck implementing his suggestion?

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

Hi Ron,

This works if I show all levels, if I add in  && $record['depth']<2 to restrict to two levels, I still get a bunch of empty list items such as:

<ul class="top">
  <li> <a href="#">Item</a>
    <ul>
      <li> </li><!--Empty Item-->
      <li> <a href="#">Item</a> </li>
      <li> <a href="#">Item</a>
        <ul>
          <li> </li><!--Empty Item-->
          <li> </li><!--Empty Item-->
          <li> </li><!--Empty Item-->
        </ul>
      </li>
      <li> <a href="#">Item</a> </li>
      <li> <a href="#">Item</a> </li>
    </ul>
    etc...

Maybe the solution is to show everything and then use css to hide the third level, messy but gets the job done.

Many thanks

Jan

Hi Jan,

I think the best way around the problem is to filter the depth level via the getCategories function instead of via PHP. Here is how I would do it:

  // load viewer library
  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';
  $dirsToCheck = array('/home/greg/www/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }


  // load records from 'animal_wiki'
  list($animal_wiki, $animal_wikiMetaData) = getCategories(array(
    'tableName'   => 'animal_wiki',
    'categoryFormat' => 'twolevel'
  ));
?>
<ul class="top">
<?php foreach ($animal_wiki as $animal): ?>
  <?php echo $animal['_listItemStart']; ?>
    <a href="/<?php echo $record['_link'];?>"><?php echo htmlspecialchars($animal['name']);?></a>   
<?php echo $animal['_listItemEnd']; ?>
<?php endforeach ?>
</ul>

So in my example I've created a dictionary of animals. I'm using the getCategories function to retrieve the records, and set an option called categoryFormat to retrieve records with a maximum depth of two (highlighted in green). The possible options for this are: showall, onelevel, twolevel, breadcrumb

Then you can use a simple foreach loop to loop through each item and display the appropriate ul/li tags. 

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

Hi Greg, Perfect!! I forgot that those functions existed for restricting categories. Nice one :)

Actually, I still had an issue where I ended up with lots of empty <li></li> tags because I can't use the hidden field (multi language with multi hidden fields depending on lang).

Managed to fix it using this hack:

.navbar li:empty {
  display: none;
  }

Thanks for all the help.