Home | Products | Consulting | Forums | Support | Order | 1-800-752-0455
  Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder:
Sub Grouping in List Views - One Way of Doing It.

 

 


InHouse
User

Apr 16, 2008, 10:10 AM

Post #1 of 8 (616 views)
Shortcut
Sub Grouping in List Views - One Way of Doing It. Can't Post

Not really a question this time, but a suggestion for others. I've worked up this simple way of sub-grouping contents of List Views. I thought it might be useful for someone.
Share and enjoy.

In the Editor, create a field to hold the sub-group names. I used a List option to limit user mistakes. I called this the "type" field. Have the list sorted by that type field.


Quote
<h2>Grouped List View</h2>
<?php
$old_group = ''; // init blank var.
foreach ($listRows 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 "<h5>$group</h5>";
}?>
<span class="archive_entry">
<a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a>
<?php echo $record['preview'] ?>
</span>
<?php $old_group = $group; // retain sub-group name before moving to new record. ?>
<?php endforeach ?>


Apologies for leaving in my own project-specific classes and HTML.

J.

(This post was edited by InHouse on Apr 17, 2008, 10:46 AM)


Dave
Staff / Moderator


Apr 17, 2008, 9:11 AM

Post #2 of 8 (605 views)
Shortcut
Re: [InHouse] Sub Grouping in List Views - One Way of Doing It. [In reply to] Can't Post

Thanks for sharing your code! :)

Dave Edis - Senior Developer
interactivetools.com


studio-a
User

Nov 4, 2008, 6:36 PM

Post #3 of 8 (441 views)
Shortcut
Re: [InHouse] Sub Grouping in List Views - One Way of Doing It. [In reply to] Can't Post

Hello,

Thanks for your coding, I have added it to my work and like it very much. I like using the list option as a choice control. I do have a question.

My question: Can you share with us a way to show ONLY ONE group and not all of them?

Thanks!


InHouse
User

Nov 5, 2008, 8:56 AM

Post #4 of 8 (430 views)
Shortcut
Re: [studio-a] Sub Grouping in List Views - One Way of Doing It. [In reply to] Can't Post

Hi studio-a.

Glad you found the snippet helpful.

As for showing one group only, I would think that you could either limit the group pulled from the database with the WHERE clause, or just use an IF statement within the FOREACH loop:


Conditional:


Code
<h2>Grouped List View</h2> 
<?php
$desired_group = 'desiredGroupNameString'; // init target var.
foreach ($listRows as $record):

if ($record['type'] == $desired_group ) { // Examine the current Type and see if it matches the desired group type.
?>
<span class="archive_entry">
<a href="<?php echo $record['_link']; ?>"><?php echo $record['title']; ?></a>
<?php echo $record['preview'] ?>
</span>
}// End If ?>
<?php endforeach ?>


I've used something similar in cases where I needed the entire list AND the single group element showing on the same page. One database call will manage both displays.

However, if you only need the one group to be shown on the page, I would think the efficient way would be to just limit what is drawn from the database using a WHERE filter on the SQL request.

Hope this helps,
J.


(This post was edited by InHouse on Nov 5, 2008, 8:57 AM)


_kate_
User


Nov 11, 2008, 7:43 AM

Post #5 of 8 (380 views)
Shortcut
Re: [InHouse] Sub Grouping in List Views - One Way of Doing It. [In reply to] Can't Post

Excellent code!! Just what I was looking for! Thanks for sharing :)

I've tried to combine this with another code which should sort the products into columns of 5 but I'm not sure how. Using the below what happens is the page displays the list of item titles, then all of the products (not grouped under their titles). Can anyone let me know what I'm doing wrong? :( The items are being sorted into columns of 5 still however...


<?php
$old_group = ''; // init blank var.
foreach ($kfiveRecords as $record):
$group = $record['brand']; // load sub-group value from record.
if ($group != $old_group) { // If different from the last sub-group value, print the sub-group name.
echo "<strong>$group</strong><br /><br />";
}?>

<td width="200" align="center" valign="top" style="padding-bottom: 16px;">

<?php echo $record['title'] ?><br />

<?php foreach ($record['brochure'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><br/>
<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>
<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>" target="_blank" class="BrochureImg">
<?php foreach ($record['thumbnail'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" alt="" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" /><br/>
<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" alt="" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" vspace="6" /><br/>
<?php else: ?>
</a><br/>
<?php endif ?>
<?php endforeach ?>
<?php endif ?>
<?php endforeach ?>

<?php foreach ($record['brochure'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><br/>
<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>
<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>" target="_blank">View Brochure ></a><br/></td>

<?php endif ?>
<?php $old_group = $group; // retain sub-group name before moving to new record. ?>
<?php endforeach ?>


<?php $maxCols=5; if (@++$count1 % $maxCols == 0): ?></tr><tr><?php endif; ?>
<?php endforeach ?>


<?php if (!$kfiveRecords): ?>
There are currently no products. Please check this page again shortly.
<?php endif ?>


(This post was edited by _kate_ on Nov 11, 2008, 8:01 AM)


Dave
Staff / Moderator


Nov 11, 2008, 3:45 PM

Post #6 of 8 (360 views)
Shortcut
Re: [_kate_] Sub Grouping in List Views - One Way of Doing It. [In reply to] Can't Post

Hi Kate,

Can you post an url and/or attach the file?

Are you sorting by group first? That's a requirement of this method.

Dave Edis - Senior Developer
interactivetools.com


_kate_
User


Nov 12, 2008, 9:54 AM

Post #7 of 8 (339 views)
Shortcut
Re: [Dave] Sub Grouping in List Views - One Way of Doing It. [In reply to] Can't Post

Hi,
Here is the file. Not sure what you mean when you say sort by groups.

Thanks!
Attachments: kfive.php (3.98 KB)


Dave
Staff / Moderator


Nov 12, 2008, 2:55 PM

Post #8 of 8 (334 views)
Shortcut
Re: [_kate_] Sub Grouping in List Views - One Way of Doing It. [In reply to] Can't Post

In the Section Editor for this section under the "Sorting" tab, what does the "Order By" field say?

You're going to want to sort by brand first before any other fields.

It's hard to get a sense of what might be wrong from the file. The code looks good from everything I can see.

If you can email me the url I can take a look for you (dave@interactivetools.com). If you send FTP and CMS login details as well it will make it easier to fix. (Email, don't post login details to the forum).

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com

 
 
 


Search for (options)
Products
CMS Builder
Article Manager
Realty Manager
Listings Manager
Order Now
Services
Priority Consulting
Support
Online Documentation
Support Forums
Support Homepage
Company Info
12 reasons to choose us!
Meet the team
Monthly newsletter
Contact Us
Toll Free: 1-800-752-0455
Phone: (604) 689-3347
Sales | Support
Conditions of Use | Privacy Policy | Copyright © interactivetools.com 2008
#201 - 2730 Commercial Drive, Vancouver BC Canada V5N 5P4