Just wondering how people set up an RSS feed to cope when there are no entries in the channel that is set to display in the feed.
Ideally, I’d like to have a {if no_results} option, as shown in the code below, which shows a fallback entry if there are no posts; but rather than show the alternate content, I just get PHP errors (presumably because there are no channel posts). Have I made a mistake, or is this not possible?
These are the errors:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: last_update
Filename: rss/mod.rss.php
Line Number: 403A PHP Error was encountered
Severity: Notice
Message: Undefined variable: edit_date
Filename: rss/mod.rss.php
Line Number: 403A PHP Error was encountered
Severity: Notice
Message: Undefined variable: entry_date
Filename: rss/mod.rss.php
Line Number: 403A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /home/username/system/codeigniter/system/core/Exceptions.php:170)
Filename: core/Common.php
Line Number: 409http://www.mysite.com/ http://www.rssboard.org/rss-specification ExpressionEngine v2.1.3 http://expressionengine.com/ empty_feed Fri, 21 Jan 2011 12:02:25 GMT
This is the RSS code:
{preload_replace:master_channel_name="event-notice"}
{exp:rss:feed channel="{master_channel_name}"}
<?xml version="1.0" encoding="{encoding}"?>
<rss version="2.0"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:admin="http://webns.net/mvcb/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>{exp:xml_encode}Site Title{/exp:xml_encode}</title>
<link>http://www.mysite.com</link>
<description>Subtitle</description>
<dc:language>{channel_language}</dc:language>
<admin:generatorAgent rdf:resource="http://expressionengine.com/" >
{exp:channel:entries channel="{master_channel_name}" limit="10" dynamic_start="on" disable="member_data|pagination"}
<item>
<title>{exp:xml_encode}{title}{/exp:xml_encode}</title>
<link>{title_permalink='events/notice'}</link>
<guid>{title_permalink='events/notice'}#When:{gmt_entry_date format="%H:%i:%sZ"}</guid>
<description><![CDATA[{event-notice-content}]]></description>
<dc:date>{gmt_entry_date format="%Y-%m-%dT%H:%i:%s%Q"}</dc:date>
</item>
{if no_results}
<item>
<title>{exp:xml_encode}A Default Welcome Title{/exp:xml_encode}</title>
<link>http://www.mysite.com/</link>
<guid>http://www.mysite.com/</guid>
<description><![CDATA[ This is a welcome message that people will read if they come to the RSS feed and there are currently no posts.
This is a welcome message that people will read if they come to the RSS feed and there are currently no posts. You can read more about our featured events on our <a href="http://www.mysite.com/features">features page</a>. ]]></description>
</item>
{/if}
{/exp:channel:entries}
</channel>
</rss>
{/exp:rss:feed}I found a workaround by removing the {if no_results} part, adding offset=“1”, making a dummy post that no one will ever see (added offset=“1” on the display page too) and added in a hardcoded Welcome post in the Feed. A bit convoluted, though.
The reason I’d like a fallback is that the posts (which are for events) are deleted once the event has expired, so it would be nice to have a placeholder post in the RSS feed when there are no scheduled events.
Thanks for any help.