List page categorized by field
3 posts by 2 authors in: Forums > CMS Builder
Last Post: March 29, 2008 (RSS)
By steve_e - March 29, 2008
I'd like to have the records of the list (or index?) page appear sorted by a field from the record.
So, for example, if the section gave details of cats, with age, name, address and breed as fields, I would like to list all Manx cats, followed by all tabby cats or whatever.
But I'd only like the field label (eg 'Manx') to appear once, as a heading. How would I set the logic for that? I've tried a couple of different 'for each' and 'if' variations but my coding skills are pretty minimal...
So, for example, if the section gave details of cats, with age, name, address and breed as fields, I would like to list all Manx cats, followed by all tabby cats or whatever.
But I'd only like the field label (eg 'Manx') to appear once, as a heading. How would I set the logic for that? I've tried a couple of different 'for each' and 'if' variations but my coding skills are pretty minimal...
Re: [steve_e] List page categorized by field
By Dave - March 29, 2008
Hi Steve,
Sort by breed first, then whatever field you want to sort on next. Then... Add this bit of code to your list records block:
Basically, we just keep a copy of the breed from the last record in $lastBreed, and if it changes we show a heading.
Hope that helps! Let me know if you need any more assistance with that.
Sort by breed first, then whatever field you want to sort on next. Then... Add this bit of code to your list records block:
<?php foreach ($listRows as $record): ?>
...
<?php if ($record['breed'] != @$lastBreed): ?>
<h1><?php echo $record['breed'] ?></h1>
<?php $lastBreed = $record['breed']; endif ?>
...
<?php endforeach ?>
Basically, we just keep a copy of the breed from the last record in $lastBreed, and if it changes we show a heading.
Hope that helps! Let me know if you need any more assistance with that.
Dave Edis - Senior Developer
interactivetools.com
interactivetools.com
Re: [Dave] List page categorized by field
By steve_e - March 29, 2008
Hi Dave -
Excellent, thanks very much!
Best wishes,
Steve.
Excellent, thanks very much!
Best wishes,
Steve.