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: [Jason] Showing content that meets certain criteria

By NigelGordijk - February 25, 2011 - edited: February 25, 2011

Perfect! Thank you both, gentlemen!

I'd like to have the headings duplicated at the top with anchored links to the relevant section on the page. I've been able duplicate the headings at the top of the page - http://www.wilmot.ca/links-websites.php - but I don't know how to create the anchored links.

This is the code that creates the line of headings at the top:

<?php $lastCategory = ''; ?>
<?php foreach ($community_linksRecords as $record): ?>
<?php if ($lastCategory != $record['category']): ?>
<?php echo $record['category:label'] ?>&nbsp;&nbsp;&nbsp;
<?php endif; ?>
<?php $lastCategory = $record['category']; ?>
<?php endforeach ?>

And this is the code - adapted from Tim - that displays the various sections beneath:

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

Any suggestions, please?
Nigel Gordijk

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