Show 1 record as title in Listpage

6 posts by 2 authors in: Forums > CMS Builder
Last Post: May 1, 2009   (RSS)

By kovali - April 30, 2009

Hi,

I have 1 section with 3 records: Category - Products - Price. The "Category" record is a pulldown list with only 4 options.

In the Listpage of the website, I want to use the record "Category" as a title above all the belonging Products, like this:

Category 1
Product A - 50.000 $
Product B - 80.000 $
Product C - 35.000 $

Category 2
Product E - 40.000 $
Product F - 70.000 $
Product G - 65.000 $

How can this be achieved please ?

Thanks,
Koen

Re: [kovali] Show 1 record as title in Listpage

By ross - April 30, 2009

Hi Koen

Thanks for posting!

I think I understand what you are trying to setup but I don't quite know if I understand how you have the database setup.

To produce a list like you have in your post though, you'll want to have that 1 section setup with three fields:

Category (Drop down list with 4 options)
Product (textfield)
Price (textfield)

Is that how you have it setup right now? The part that's throwing me off is that you said your section has three records in it. Did you mean the section has three fields in it?

Let me know and we can go over some code to get things going like you need.

Thanks!
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] Show 1 record as title in Listpage

By kovali - April 30, 2009

Hi Ross,

Sorry if my explanation got you confused, I should have written fields instead of records...

Yes, you are very right about the setup, I have 3 fields like that in the section.

Looking forward for your code, thanks for your help.

Koen

Re: [kovali] Show 1 record as title in Listpage

By ross - April 30, 2009

Hi Koen

Thanks for clearing that up :).

The first thing here is that you'll want to change the ordering of your records in this section so they sort by the category name. You can do that in the section editor or you can do it on this page in the viewer code.

Next. you'll need to create a new variable just before you start the foreach loop that displays all your listings. Something like this: $lastCategory = "";

Then, inside your foreach loop, you'll need to check the current category name against $lastCategory. That will look something like this:

if ($record['category'] != $lastCategory) {
display category name
}

After that bit you'll display the other two fields.

Does that make sense? Give it a shot and let me know how you make out :).
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] Show 1 record as title in Listpage

By kovali - May 1, 2009

Ok Ross, I tried it but now it shows the Category name with every Product, like:

[font "Verdana"]Category 1
Product A - 50.000 $
Category 1
Product B - 80.000 $
Category 1
Product C - 35.000 $

Category 2
Product E - 40.000 $
Category 2
Product F - 70.000 $
Category 2
Product G - 65.000 $


[font "Verdana"]What I want is:

[font "Verdana"]Category 1
Product A - 50.000 $
Product B - 80.000 $
Product C - 35.000 $

Category 2
Product E - 40.000 $
Product F - 70.000 $
Product G - 65.000 $


[font "Verdana"]This is my code:

<?php $lastCategory = ""; ?>
<?php foreach ($immo_te_koopRecords as $record): ?>
<?php if ($record['status'] == "Beschikbaar"): ?>
<?php if ($record['categorie'] != $lastCategory): ?> <?php echo $record['categorie'] ?><?php endif ?>
<li>
<div class="img"><a href="<?php echo $record['_link'] ?>" ><?php foreach ($record['foto_s'] as $upload): ?><a href="<?php echo $record['_link'] ?>"><img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="<?php echo $record['title'] ?>" /></a><?php break ?><?php endforeach; ?></div>

<div class="tit"><a href="<?php echo $record['_link'] ?>" class="txt"><strong><?php echo $record['gemeente'] ?>:&nbsp;<?php echo $record['title'] ?></strong></a></div>

<div class="cont"><span class="style6"><?php echo textLimit($record['content'],280) ?></div>

<div class="cont"><span class="style8"><strong>Prijs:</strong> <?php echo $record['verkoopprijs'] ?>&nbsp;EUR</span> <span class="style7">&raquo;</span>&nbsp;<a href="<?php echo $record['_link'] ?>" class="txt">Details</a></div>
</li>
<?php else: ?>
<?php if ($record['categorie'] != $lastCategory): ?> <?php echo $record['categorie'] ?><?php endif ?>
<li>
<div class="img"><?php foreach ($record['foto_s'] as $upload): ?><img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="<?php echo $record['title'] ?>" /><?php break ?><?php endforeach; ?></div>

<div class="tit"><strong><?php echo $record['gemeente'] ?>:&nbsp;<?php echo $record['title'] ?></strong></div>

<div class="cont"><span class="style6"><?php echo textLimit($record['content'],280) ?></div>

<div class="cont"><span class="style9"><strong><?php echo $record['status'] ?></strong> </span> </div>
</li>
<?php endif ?>
<?php endforeach; ?>