RSS help

14 posts by 3 authors in: Forums > CMS Builder
Last Post: December 15, 2011   (RSS)

Hello all,
I want to add a RSS feed to a site I am working on.
I used the http://www.interactivetools.com/docs/cmsbuilder/rss_feeds.html as a template. It validated and looked like it would work. Yet when I run some test posts they do not show up in the feed. I am pulling records from 3 different areas of input. That is where I think the wheels fall off my code. I attached the php file if anyone would like to give it a look and point me in the right direction.

Thank you
Chris
Attachments:

rss-xml_003.php 3K

Re: [towtimes] RSS help

By Jason - December 14, 2011

Hi Chris,

If you are receiving no errors on the page, then you are probably just not returning any records in $truckRecords.

A couple of things I noticed:

- You do a query to get location records, but they are not used anywhere else in the script.

- You are retrieving a single accounts record based on a number in the URL string. If there is nothing in the string, it will use record number 1. Since your other 2 queries are based on this accounts record, if no number is being passed in the URL, that could explain the problem.

Try using debugSql on your queries to see what their actually executing to see if there are any clues there.

Let us know what you find.

Thanks,
---------------------------------------------------
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] RSS help

Thanks for the tips I did get rid of that locations records code.I also removed the single record string. I want to show the 5 most current listings at a time. One issue I see is the <?php foreach ($trucksRecords as $record): ?> I need to pull from trucks and the account field. How do I add both fields to that statement. I attached the new revised code.
Attachments:

rss-xml_004.php 3K

Re: [towtimes] RSS help

Hi towtimes,

One thing that I noticed is that you have one too many closing ")" after the line 'equipment_manufacturers' => 'equipment_manufacturerNum')

Here are some recipes on RSS feeds from my CMSB Cookbook http://www.thecmsbcookbook.com that might help.

Best,

Jerry Kornbluth

CREATING AN RSS FEED FOR A MULTI-RECORD SECTION

If you’ve had mixed results trying to create an RSS feed for a multi-record section you’re not alone. There seem to be many
“details” for the “Devil” to hide in.

Here’s an approach that worked for me which you can build on for your own uses.

For a table called “current_events”, I wanted to show the most current records in my events list and limit the RSS display to only the
2 most recently created records. I also wanted a masthead logo and a link to the main event’s page to appear at the top of the feed.

The code that I finally came up with for the XML file I named happening-now-rss.xml.php is:

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

<?php

require_once "/hsphere/local/home/apbcweb/artistsofpalmbeachcounty.org/cmsAdmin/lib/viewer_functions.php";

list($current_eventsRecords, $current_eventsMetaData) = getRecords(array(
'Table name' => 'current_events',
'orderBy' => 'createdDate DESC',
'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>


<language>en-us</language>

<item>
<title>www.artistsofpalmbeachcounty.org</title>
<description>
<![CDATA[
<div align="left">
<a href="http://www.artistsofpalmbeachcounty.org"><img src="http://www.artistsofpalmbeachcounty.org/images/APBC-LOGO.png" /></a><br />These
are the latest two events that were added to our <b>Happening Now</b> events list. For a complete list of events <a
href="http://www.artistsofpalmbeachcounty.org/events.php" target="_blank">click here</a>.<br /><b><i>The date is when the event was
added.</i></b></div>
]]>
</description>
<guid isPermaLink="true">http://www.artistsofpalmbeachcounty.org</guid>
<pubDate><?php echo date('r'); ?></pubDate>
</item>

<?php foreach ($current_eventsRecords as $record): ?>
<item>
<?php $title = htmlspecialchars($record['title']); ?>
<title><![CDATA[<?php echo strtoupper($title); ?><?php if ($record['end_date']): ?> - Now through <?php echo $record['end_date'] ?><?php
endif; ?> ]]></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['createdDate'])) ?></pubDate>

<guid isPermaLink="true">http://www.artistsofpalmbeachcounty.org<?php echo $record['_link'] ?></guid>
</item>
<?php endforeach ?>

</channel>
</rss>


Here are some of the things that I learned along the way.

This code in the example above makes Atom feeds happier.:

<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" />


You can include an image in your channel (not in an item) but it may or may not appear at the upper right corner of your feed depending on
the feed reader that you’re using.

If you’re embedding an image in the <channel> area it’s preferable to have your image title match the channel title.

If you want to include a logo image, you can try to include it in a separate <item> instead if in the channel area (it will not always
appear at the top of your feed unless you add <pubDate><?php echo date('r'); ?></pubDate> to that item).

The date format "D, d M Y H:i:s O insures that your date will render in the appropriate format for RSS feeds.


VALIDATING AN RSS FEED

You should validate your RSS feed before you publish it. You can do that here:

http://www.validator.w3.org/feed/

You can find out more about the tags that are available for use in you feed at:

http://www.rss-specifications.com/

EMBEDDING AN IMAGE IN AN RSS FEED

RSS feeds can be finicky, but this should work to display an image as part of an item in the foreach loop.

<description>
<![CDATA[

<p><u>Here is an image thumbnail</u> </p>

<?php foreach ($record['image'] as $upload): ?>
<img src="http://www.my_web_site.com<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo
$upload['thumbHeight'] ?>" alt="" />
<?php endforeach ?></p>

<p align="center"><strong><font color="#ba1419">My First Image</font></strong></p>
]]>
</description>


In general, any time you want to treat code as "code" in an RSS feed, you need to surround the code with CDATA tags.

Note: You'll have to add the URL to change the relative image thumbURLpath location to an absolute URL.

Any code (formatting, etc) within the CDATA tags will be treated as code and should render correctly.


RSS FEED CAVEATS

Here are a few things that I’ve discovered that may save you some time.

You can only add CDATA to fields in an <item> area

Some readers and browsers will not render an <item> correctly without a <guid> or a <title>
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] RSS help

Thank you for the help I did have to many closing tags. Now when I cleaned up my code to match your example I get this error message. <?xml version="1.0" encoding="UTF-8"?>Couldn't start session! 'session_start(): Cannot send session cache limiter - headers already sent (output started at /home/towingeq/public_html/rss.xml.php:1)'!
you can look at my file in action at http://towingequipmentsearch.com/rss.xml.php
I attached the new code. Sorry to be a pain coding is just not my strong point.
Attachments:

rss-xml_005.php 3K

Re: [towtimes] RSS help

Hi Towtimes,

I'm not a great coder either.

You might try:

session_write_close ();
after your

require_once("./includes/functions.inc.php");
[session_write_close ();


And I think you might be missing a . in the include path

"../includes/functions.inc.php");

Jerry Kornbluth
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] RSS help

Thank you for the tips. I added the session_close (); part and nothing bad happened.
I tired the extra . and that did not go over to well. I still have the same error message as I did before. I will keep trying different code until it works.

Re: [towtimes] RSS help

does it give an error without the extra include?
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] RSS help

I have been playing around with the code and now I get a new error message. That might be progress haha.
getRecords(trucks) errors<br/>

I think now I have the RSS formatting correct but not the code to pull from the database.
I attached the new file.

Thank you