Showing content that meets certain criteria

5 posts by 3 authors in: Forums > CMS Builder
Last Post: February 25, 2011   (RSS)

I have a single section of CMSB that is broken down into several categories; e.g. Sports, Places of Worship, and Schools. I'd like to display all of the content on a single page, but shown under the appropriate headings. I can get all of the content to show under each heading, but I don't know how to only display the sport content under Sports, the places of worship under Places of Worship, etc.

http://www.wilmot.ca/links-websites.php

This is the code that displays the content:

<?php foreach ($community_linksRecords as $record): ?>
<p><strong><a href="<?php echo $record['content'] ?>"><?php echo $record['title'] ?></a></strong></p>
<?php endforeach ?>
<?php if (!$community_linksRecords): ?>
<?php endif ?>

This is repeated under every subheading on the page.

Any ideas how to show the appropriate content in the right place, please?
Nigel Gordijk

Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net
Attachments:

links-websites.php 14K

Re: [NigelGordijk] Showing content that meets certain criteria

Hi Nigel.

Do you have a "categories" field in the editor?

If so, sort by categories.ie.
// load records
list($community_linksRecords, $community_linksMetaData) = getRecords(array(
'tableName' => 'community_links',
'orderBy' => 'category+0 ASC',

));


NB. If your categories are numbers , add the "+0" so you dont get 1,10,11,12,2,3,4,5 etc

Then;
<?php $lastCategory = ''; ?>
<?php foreach ($community_linksRecords as $record): ?>
<?php if ($lastCategory != $record['category']): ?>
<h1><?php echo $record['category:label'] ?></h1>
<?php endif; ?>
<p><strong><a href="<?php echo $record['content'] ?>"><?php echo $record['title'] ?></a></strong></p>
<?php $lastCategory = $record['category']; ?>
<?php endforeach ?>

Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Showing content that meets certain criteria

Hi, Tim.

There is a category dropdown menu for my client to choose which section the record belongs in. These are words, not numbers:

Sports
Places of Worship
Schools
Libraries
Community Groups
Newspapers
Tourism

Will your system only work with numbers?
Nigel Gordijk

Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net

Re: [NigelGordijk] Showing content that meets certain criteria

By Jason - February 25, 2011

Hi Nigel,

That code should still work for you, just don't add the +0 in the orderBy clause,

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/