Showing only 2 most recently updated records in an RSS feed

3 posts by 2 authors in: Forums > CMS Builder
Last Post: February 2, 2010   (RSS)

Hi all,

Well I’m lost again.

I’ve been trying to create an RSS feed (my first) that shows the most current records in an events list, and limit the RSS display to only the 2 most recently updated records.

This is the code that I’ve come up with so far. It limits the display to 2 records, but only shows the top 2 records in my records list, regardless of their updatedDate date.

Any suggestions as to how I would modify the code show the 2 most recently updated records would be appreciated.

Thanks,

Jerry Kornbluth

<?php header('Content-type: application/xml; charset=utf-8'); ?>
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>

<?php
require_once "/my_path_to/lib/viewer_functions.php";

list($current_eventsRecords, $current_eventsMetaData) = getRecords(array(
'tableName' => 'current_events',
'limit' => '2',
));

?>

<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<atom:link href="http://www.artistsofpalmbeachcounty.org/rss/happening-now-rss.xml.php" rel="self" type="application/rss+xml" />
<title>ARTISTS OF PALM BEACH COUNTY - HAPPENING NOW RSS FEED</title>
<link>http://www.artistsofpalmbeachcounty.org/events.php</link>
<description>Arts Events Worth Knowing About</description>
<image>
<title>ARTISTS OF PALM BEACH COUNTY - HAPPENING NOW RSS FEED</title>
<url>http://www.artistsofpalmbeachcounty.org/images/APBC-LOGO.png</url>
<link>http://www.artistsofpalmbeachcounty.org/events.php</link>
</image>

<language>en-us</language>

<?php foreach ($current_eventsRecords as $record): ?>
<item>
<?php $title = htmlspecialchars($record['title']); ?>
<title><?php echo strtoupper($title); ?></title>
<link>http://www.artistsofpalmbeachcounty.org<?php echo $record['_link'] ?></link>
<description><?php echo htmlspecialchars($record['rss_description']); ?></description>
<pubDate><?php echo date("D, d M Y H:i:s O", strtotime($record['updatedDate'])) ?></pubDate>
<guid isPermaLink="true">http://www.artistsofpalmbeachcounty.org<?php echo $record['_link'] ?></guid>
</item>
<?php endforeach ?>


</channel>
</rss>

Any suggestions appreciated.
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Showing only 2 most recently updated records in an RSS feed

By Damon - February 2, 2010

Hi,

You can either add your sort options directly into the viewer (template) or add the sort options within CMS Builder in the Section Editor, and then under the Sorting tab for "Current Events".

Here is the code to add to the viewer:

'orderBy' => 'updatedDate DESC',

Give that a shot.
Cheers,
Damon Edis - interactivetools.com

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