Showing content that meets certain criteria
5 posts by 3 authors in: Forums > CMS Builder
Last Post: February 25, 2011 (RSS)
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?
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 Toledoh - February 24, 2011
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 ?>
Tim (toledoh.com.au)
Re: [Toledoh] Showing content that meets certain criteria
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?
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
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/
Re: [Jason] Showing content that meets certain criteria
By NigelGordijk - February 25, 2011 - edited: February 25, 2011
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'] ?>
<?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?
Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net