group sub categories

4 posts by 2 authors in: Forums > CMS Builder
Last Post: July 18, 2008   (RSS)

By IronVictory - July 17, 2008

I am trying to display "sub categories" grouped on a page like this:

Main category title
Sub category 1 title
- product thumbnail
- product thumbnail
- product thumbnail
Sub category 2 title
- product thumbnail
- product thumbnail
- product thumbnail

I have a list field set up as 'sub_category' in the 'products' section.
How can I group the sub category products on the main category page?

Re: [IronVictory] group sub categories

By Dave - July 17, 2008

Hi IronVictory,

Depending on how your list page is setup, the easiest way to group them might be to just sort by subcategory and then title on your list page. Your order by might look like this (in red):

list($records, $recordMetaData) = getRecords(array(
'tableName' => 'products',
...
'orderBy' => 'sub_category, title',
...
));


If that doesn't do it let me know some more details and we'll help you figure it out!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] group sub categories

By IronVictory - July 17, 2008

Hi Dave,
This is what I have for the viewer and it just repeats. I need $record['sub_category'] as the title, then the thumbnails listed below.

<?php foreach ($productsRecords as $record): ?>

<div class="prod_title"><?php echo $record['sub_category'] ?> <?php echo $record['category'] ?></div>

<?php foreach ($record['product_image'] as $upload): ?>
<div class="prodlist"><a href="<?php echo $record['_link'] ?>&category=Sinks"><img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="<?php echo $record['productName'] ?>" border="0" /></a><br/>
<?php echo $record['model'] ?></div>
<?php endforeach ?>

<?php endforeach; ?>