Navigation List Issue

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

Hi there,

Have been having probs debugging this and I think I am running into issues with how _listItemStart and _listItemEnd work.

Here is my code:

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

And here is what the output looks like with comments showing the missing list tags:

<ul class="top">
  <li><a href="#">Top Item</a></li>
  <li><a href="#">Top Item</a>
    <ul>
      <li><a href="#">Sub Item</a></li>
      <li><a href="#">Sub Item</a><!-- missing </li> has 3rd level under here -->
      <li><a href="#">Sub Item</a></li>
    </ul>
  </li>
  <li><a href="#">Item</a>
    <ul>
      <li><a href="#">Sub Item</a></li>
      <li><a href="#">Sub Item</a><!-- missing </li> has 3rd level under here -->
    </ul>
  </li>
  <li><a href="#">Item</a></li>
  <li><a href="#">Item</a>
    <ul>
      <li><a href="#">Sub Item</a></li>
      <li><a href="#">Sub Item</a></li>
      <li><a href="#">Sub Item</a><!-- missing </li> has 3rd level under here -->
    <!-- missing closing tags </ul></li> here -->
</ul>

I believe part of the problem may be due to restricting to two levels using $record['depth']<2

Any suggestions?

Many thanks!

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 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.