syndicate or RSS feeds

15 posts by 6 authors in: Forums > CMS Builder
Last Post: June 10, 2010   (RSS)

By loccom - January 17, 2008

Hi

Is is possible to syndicate the info from a news page in CMSB like AM? or a RSS feed?

If it is possible would support be able to post instructions please?

thanks

Re: [steveo] syndicate or RSS feeds

By Dave - January 18, 2008

Hi Steveo,

You sure can. Basically you create a regular "list viewer" and then use RSS tags instead of HTML tags. Here's an example I created for an article section I have (I called it articleRSS.php):

A few things to note:
- Put the first block of code at the top of the page so it loads first
- set the pageNum option to 1 so it always shows the first page of results
- set the perPage option to however many articles you want in your feed
- make sure the viewer url is starts with http://

Full details on the RSS spec and various fields and options can be found here: http://cyber.law.harvard.edu/rss/rss.html#ltguidgtSubelementOfLtitemgt

<?php // Load record list
require_once "C:/www/sb/core2/admin/lib/viewer_functions.php";
$options = array();
$options['tableName'] = 'article';
$options['titleField'] = 'title';
$options['viewerUrl'] = 'http://www.example.com/articlePage.php';
$options['perPage'] = '10';
$options['orderBy'] = 'date DESC, title';
$options['pageNum'] = '1';
list($listRows, $listDetails) = getListRows($options);

echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
?>
<rss version="2.0">
<channel>
<title>PUT YOUR SITE NAME HERE</title>
<link>http://EXAMPLE.COM/YOUR/URL/HERE/</link>
<description>YOUR SITE DESCRIPTION GOES HERE</description>
<pubDate><?php echo date('r'); ?></pubDate>
<language>en-us</language>

<?php foreach ($listRows as $record): ?>
<item>
<title><?php echo htmlspecialchars($record['title']) ?></title>
<link><?php echo $record['_link'] ?></link>
<description><?php echo htmlspecialchars($record['summary']); ?></description>
<pubDate><?php echo date("r", strtotime($record['date'])) ?></pubDate>
<guid isPermaLink="true"><?php echo $record['_link'] ?></guid>
</item>
<?php endforeach ?>

</channel>
</rss>


Give it a try and let me know how it goes. Let me know if you need more details about anything or if I can be more clear.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] syndicate or RSS feeds

By loccom - January 18, 2008

thanks dave... when i finishing setting up i will give this a go. Exactly what i am looking for.

Re: [Berkowitz] syndicate or RSS feeds

By Dave - February 27, 2008

What's giving you the errors? My FireFox and IE7 didn't report any errors.

I also tried this W3C Validator here and pasted in the code:
http://validator.w3.org/feed/#validate_by_input

It said it was valid (but recommended adding a tag for atom:link feeds or something like that).
Dave Edis - Senior Developer
interactivetools.com

Re: [Berkowitz] syndicate or RSS feeds

By Dave - February 27, 2008

Thanks for the link. The W3C Feed Validator shows some errors for that one:

http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Fwww.1id.be%2Fnewsrss.php

Try adding this to the top after the <?php to set that charset and content type:

<?php

header('Content-type: application/xml; charset=utf-8');


Then try the link in the feed validator and browser again and see what error or problems remain (hopefully none).
Dave Edis - Senior Developer
interactivetools.com

Re: [Berkowitz] syndicate or RSS feeds

By Dave - February 28, 2008

Hurray! :)
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] syndicate or RSS feeds

By nikkijones - March 13, 2008 - edited: March 13, 2008

Hi Dave,

I;m also having a problem settting this up. Maybe i'm just tired and missing something really simple, i dunno. My page is called articlerss.php. I;m trying to get the news articles that are posted.


Here is my code:

<?php
header('Content-type: application/xml; charset=utf-8');
require_once "/home/fhlinux152/a/allianceinpartnership.co.uk/user/htdocs/cmsAdmin/lib/viewer_functions.php";
$options = array(); // NOTE: see online documentation for more details on these options
$options['tableName'] = 'news'; // (REQUIRED) MySQL tablename to list record from. Example: 'article';
$options['titleField'] = 'title'; // (optional) MySQL fieldname used in viewer url for search engines. Example: 'title' would display: viewer.php/article_title_here-123
$options['viewerUrl'] = 'http://www.allianceinpartnership.co.uk/newsPage.php'; // (optional) URL of viewer page. Example: '/articles/view.php';
$options['perPage'] = '10'; // (optional) The number of records to display per page. Example: '5'; Defaults to 10.
$options['orderBy'] = 'title'; // (optional) Fieldnames to sort by. Example: 'field1, field2 DESC, field3';
$options['pageNum'] = '1'; // (optional) Page number of results to display. Example: '1'; Defaults to ?page=# value, or 1 if undefined
list($listRows, $listDetails) = getListRows($options);
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
?>
<rss version="2.0">
<channel>
<title>PUT YOUR SITE NAME HERE</title>
<link>http://EXAMPLE.COM/YOUR/URL/HERE/</link>
<description>YOUR SITE DESCRIPTION GOES HERE</description>
<pubDate><?php echo date('r'); ?></pubDate>
<language>en-us</language>
<?php foreach ($listRows as $record): ?>
<item>
<title><?php echo htmlspecialchars($record['title']) ?></title>
<link><?php echo $record['_link'] ?></link>
<description><?php echo htmlspecialchars($record['summary']); ?></description>
<pubDate><?php echo date("r", strtotime($record['date'])) ?></pubDate>
<guid isPermaLink="true"><?php echo $record['_link'] ?></guid>
</item>
<?php endforeach ?>
</channel>
</rss>


...all i get is feed code error [:(]

Cheers,
nikki.

Re: [nikkijones] syndicate or RSS feeds

By Dave - March 13, 2008

Do you have a url to the test page so I can check the feed error?
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] syndicate or RSS feeds