display category menu in <ul> format

21 posts by 6 authors in: Forums > CMS Builder
Last Post: August 9, 2010   (RSS)

By markr - March 28, 2010

I want to use a category section as a <ul> format list for a navigation menu. Is this still the best guide?


http://www.interactivetools.com/forum/gforum.cgi?post=64259

Re: [markr] display category menu in <ul> format

By Donna - March 29, 2010

Hi Mark!

Yup, you've got it. One of the code snippets Dave mentioned is specifically for <ul> lists, and will output the <li> tags for you, with the <?php echo $categoryRecord['_listItemStart'] ?> code. Try that and it should work for you. :)
Donna

--
support@interactivetools.com

Re: [Donna] display category menu in <ul> format

By markr - April 5, 2010

So my follow-up is... is there a way to write a foreach loop dependent on depth?

In my example below, Apple has no children and uses the class "parent".

Orange has children: it needs a different class and a list for the children.

I do not need to go deeper than 1 child.

Example:

<a class="parent" href="#">Apple</a>

<a class="parent withChildren" href="#">Orange</a>
<div class="submenu">
<ul>
<li><a href="#">Blood</a></li>
<li><a href="#">Navel</a></li>
</ul>
</div>

Re: [markr] display category menu in <ul> format

By Dave - April 9, 2010 - edited: May 5, 2010

Hi markr,

In v2.03 we added some "pseudo-fields" called _hasParent and _hasChild for doing tests like that. So you can say:

<ul>
<?php foreach ($categoryRecords as $categoryRecord): ?>
<?php echo $categoryRecord['_listItemStart'] ?>

<?php $aClass = ""; ?>
<?php if (!$categoryRecord['_hasParent']) { $aClass .= "parent "; } ?>
<?php if ($categoryRecord['_hasChild']) { $aClass .= "withChildren "; } ?>


<a class="<?php echo $aClass ?>" href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>

<?php echo $categoryRecord['_listItemEnd'] ?>
<?php endforeach; ?>
</ul>


Do those help any?

Update: Fixed code typo
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] display category menu in <ul> format

By design9 - May 5, 2010

Dave,

I am trying to accomplish the same structure here for my category menu within the <ul>.

I am getting the following parse error:

Parse error: parse error, unexpected '<' in D:\hosting\member\charlottepar\site1\test\sitemap\index.php on line 225

Here is my code:

<ul>
<?php foreach ($sitemaplistRecords as $record): ?>
<?php echo $record['_listItemStart'] ?>
<?php $aClass = "";
<?php if (!$record['_hasParent']) { $aClass .= "parent "; } ?>
<?php if ($recordd['_hasChild']) { $aClass .= "withChildren "; } ?>

<span class="body"><a class="<?php echo $aClass ?>" href="<?php echo $record['url'] ?>"><?php echo $record['name'] ?></a></span>

<?php echo $record['_listItemEnd'] ?>
<?php endforeach; ?>
</ul>

Can you help me figure what is wrong?

Thanks!

April

Re: [Dave] display category menu in <ul> format

By design9 - May 5, 2010

Dave,

I had tried that but then I get undefined index errors:
see page:
http://www.charlotteparent.com/test/sitemap/index.php

Here is my code now:
<ul>
<?php foreach ($sitemaplistRecords as $record): ?>
<?php echo $record['_listItemStart'] ?>
<?php $aClass = ""; ?>
<?php if (!$record['_hasParent']) { $aClass .= "parent "; } ?>
<?php if ($recordd['_hasChild']) { $aClass .= "withChildren "; } ?>

<span class="body"><a class="<?php echo $aClass ?>" href="<?php echo $record['url'] ?>"><?php echo $record['name'] ?></a></span>

<?php echo $record['_listItemEnd'] ?>
<?php endforeach; ?>
</ul>

Thanks!
April

Re: [apdance9] display category menu in <ul> format

By Dave - May 6, 2010

Can you attach your index.php?

Thanks!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] display category menu in <ul> format

By design9 - May 6, 2010

Sure, here it is.

Thanks!
A~
Attachments:

index_016.php 42K

Re: [apdance9] display category menu in <ul> format

By rconring - May 6, 2010

I think the problem is with your viewer code:
list($sitemaplistRecords, $sitemaplistMetaData) = getRecords(array(

Assuming the table sitemaplist is a category menu, you should use:
list($sitemaplistRecords, $sitemaplistSelected) = getCategories(array(
Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987