Grouping listings by month with header

4 posts by 3 authors in: Forums > CMS Builder
Last Post: November 3, 2008   (RSS)

By gkornbluth - October 26, 2008

I have a list of events that are pulled from a multi record editor and displayed on a listings page, sorted by date.

I’d like to be able to group the listings by month (in ascending order) with a “month” heading (probably an image) at the top of each month’s group.

If there are no listings for a particular month then no heading would be shown.

Anyone have an elegant solution?

Sorry, I just can’t seem to get my head around this one.


Jerry Kornbluth
The first CMS Builder reference book is now available on-line!

Take advantage of a free 3 month trial subscription, only for CMSB users, at:

Re: [gkornbluth] Grouping listings by month with header

By Kenny - October 26, 2008 - edited: October 26, 2008

Here's one built in a table you could use:

You'll need to replace my code with your code -

$lastCategory = "";
foreach ($eventRecords as $record):
$showHeader = false;
if ($record['month'] != $lastCategory) {
$lastCategory = $record['month'];
$showHeader = true;
<?php if ($showHeader): ?>
<td><?php echo $record['month'] ?></td>
<?php endif ?>
<td><?php echo $record['title'] ?></td>
<td><?php echo $record['content'] ?></td>
<?php endforeach; ?>


Hope that helps -


Re: [gkornbluth] Grouping listings by month with header

By InHouse - November 3, 2008