finding last child entry in category menu with 2 levels

5 posts by 2 authors in: Forums > CMS Builder
Last Post: August 15, 2011   (RSS)

By buttermilk - August 13, 2011

Hi All,

I was wondering if anybody knows how to get php to find out if an entry in a foreach loop is the last child of the parent entry. So, if I had 3 level 0 entries and each had 4 or 5 child entries (depth 1), how could I vary the output for the final entry in each main record?

I imagine an "if" statement would work here, but I'm not really sure how to structure it.

Any help is appreciated!

Ian

Re: [buttermilk] finding last child entry in category menu with 2 levels

By Jason - August 15, 2011

Hi Ian,

You can use the _isLastChild field to determine this. So for example:

<?php foreach ($categoryRecords as $category): ?>
<?php if ($category['_isLastChild']): ?>
//output when the current record is the last child
<?php else: ?>
// output when the current record is not the last child
<?php endif ?>
<?php enforeach?>



Hope this helps get you started.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [buttermilk] finding last child entry in category menu with 2 levels

By Jason - August 15, 2011

Hi,

_isLastChild is a pseudo field that get's created when you use getCategories.

Try this change:

// load records
list($speciesRecords, $speciesMetaData) = getCategories(array(
'tableName' => 'species',
));


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] finding last child entry in category menu with 2 levels

By buttermilk - August 15, 2011

Ah! I'm sure that will come in handy in the future.

Works perfectly. Thanks, Jason!

Ian