SORTING BY GROUP AND INSERTING GROUP HEADINGS IN A LIST VIEWER - Aug 2nd, 2010
|
If you’d like to display group headings on your list page here’s one approach:
For this example, a multi-record editor, called “events” has the following fields:
Title (a text field) Type (a pull down list of “Groups” to minimize entry errors) Starting Date (a date field) * in the viewer, only the Month, Day and Year are visible Preview (a short description of the event for the listing page)
In your application, you could add a full description of the event for the details page, images, etc.
The sort is by Type (ASC)ending and then by Start Date (ASC)ending
On the list viewer page the following code appears where you want your list to appear .
<?php $old_group = ''; // init blank var. foreach ($eventsRecords as $record): $group = $record['type']; // load sub-group value from record. if ($group != $old_group) { // If different from the last sub-group value, print the sub-group name. echo "<h2>$group</h2>"; }?> <a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a> <?php echo $record['preview'] ?> <br /><br /> <?php $old_group = $group; // retain sub-group name before moving to new record. ?> <?php endforeach ?>
If you want to use alternate text or graphics to represent your groups you could use the following.
For Text:
<?php $old_group = ''; // init blank var. foreach ($eventsRecords as $record): $group = $record['type']; // load sub-group value from record. if ($group != $old_group && $record['type'] == "Group 1") { // If different from the last sub-group value, and equals Group 1, print the sub-group name. echo "<h2>Group 1 text </h2>";}
if ($group != $old_group && $record['type'] == "Group 2") { echo "<h2>Group 2 text</h2>";}
if ($group != $old_group && $record['type'] == "Group 3") { echo "<h2>Group 3 text</h2>";}
if ($group != $old_group && $record['type'] == "Group 4") { echo "<h2>Group 4 text</h2>";} ?> <a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a> <?php echo $record['preview'] ?> <br /><br /> <?php $old_group = $group; // retain sub-group name before moving to new record. ?> <?php endforeach ?>
To display images instead of text for the headings, one approach would be to create a separate single record editor called “Graphics” with each image as a separate upload field named Group 1 Graphic, Group 2 Graphic, etc., and use something like this on the viewer page (don’t forget to add the getrecord call at the top of your page).
<?php $old_group = ''; ?>
<?php foreach ($eventsRecords as $record): ?>
<?php $group = $record['type']; ?> <?php if ($group != $old_group && $record['type'] == "Group1"): ?>
<div align="center"><?php foreach ($graphicsRecord['group_1_graphic'] as $upload): ?> <img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt='' /><br /><br /></div> <?php endforeach ?> <?php endif ?>
<?php if ($group != $old_group && $record['type'] == "Group 2"): ?>
<div align="center"><?php foreach ($graphicsRecord['group_2_graphic'] as $upload): ?> <img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt='' /><br /><br /></div> <?php endforeach ?> <?php endif ?>
<?php if ($group != $old_group && $record['type'] == "Group 3"): ?> <div align="center"><?php foreach ($graphicsRecord['group_3_graphic'] as $upload): ?> <img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt='' /><br /><br /></div>
<?php endforeach ?> <?php endif ?>
|
The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact
Interactive Tools for information on the downloading of the software or the purchasing of licenses.