RSS feed error message/Headlines from multiple sections

18 posts by 4 authors in: Forums > CMS Builder
Last Post: July 30, 2009   (RSS)

By NigelGordijk - July 17, 2009 - edited: July 17, 2009

Hi, All.

I have two CMS Builder issues I'd like to sort out.

======

1. RSS feed: I've got this to work on http://www.yallaf1.com, and the feeds are appearing when I add them to Google and Yahoo. However, I'm getting the following error message, which appears under the headline link:

"Notice: Undefined index: summary in /home/yallaf5/public_html/rss.xml.php on line 22"

This is the code that I'm using in the file called rss.xml.php:

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

require_once "/home/yallaf5/public_html/cmsAdmin/lib/viewer_functions.php";

list($top_storiesRecords, $top_storiesMetaData) = getRecords(array(
'tableName' => 'top_stories',
));

?>
<rss version="2.0">
<channel>
<title>YallaF1 - Daily Formula 1 News</title>
<link>http://www.yallaf1.com</link>
<description>YallaF1.com Daily Formula 1 News</description>
<pubDate><?php echo date('r'); ?></pubDate>
<language>en-us</language>
<?php foreach ($top_storiesRecords as $record): ?>
<item>
<title><?php echo htmlspecialchars($record['title']) ?></title>
<link>http://www.yallaf1.com<?php echo $record['_link'] ?></link>
<description><?php echo htmlspecialchars($record['summary']); ?></description>
<pubDate><?php echo date("r", strtotime($record['date'])) ?></pubDate>
<guid isPermaLink="true">http://www.yallaf1.com<?php echo $record['_link'] ?></guid>
</item>
<?php endforeach ?>
</channel>
</rss>

Can anyone tell me where I'm going wrong, please?

======

2. On the homepage - http://www.yallaf1.com - is a column of headlines under the title "Daily News". These headlines all come from a single section of the site that is controlled with CMSB. Is there a way of collating headlines from more than one section so that they are all chronological? Therefore, just as an example, there might be two "Top Stories" headlines next to each other because they've been added most recently, followed by a headline from "Daily News", two from "Blog", etc.

Thanks!
Nigel Gordijk

Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net

Re: [NigelGordijk] RSS feed error message/Headlines from multiple sections

By isdoo - July 17, 2009

Assuming that your description field is called summary rather than say content, then I can't see why this line should not work - however confirm to see the field name within your table.

<description><?php echo htmlspecialchars($record['summary']); ?></description>

incidentally, I use, the code below to limit my content to 75 characters rather than posting the ful article in the RSS feed.
<?php

// Usage: < ?php print maxWords($content, 25); ? >
function maxWords($textOrHtml, $maxWords) {
$text = strip_tags($textOrHtml);
$words = preg_split("/\s+/", $text, $maxWords+1);
if (count($words) > $maxWords) { unset($words[$maxWords]); }
$output = join(' ', $words);

return $output;
}
?>


<?php foreach ($news1Records as $record): ?>
<item>
<title><?php echo htmlspecialchars($record['title']) ?></title>
<link>http://www.fansfocus.com<?php echo $record['_link'] ?></link>
<description><?php echo maxWords(htmlspecialchars($record['content']), 75); ?>....</description>
<pubDate><?php echo date("r", strtotime($record['date'])) ?></pubDate>
<guid isPermaLink="true">http://www.fansfocus.com<?php echo $record['_link'] ?></guid>
</item>
<?php endforeach ?>

Re: [isdoo] RSS feed error message/Headlines from multiple sections

By NigelGordijk - July 17, 2009 - edited: July 17, 2009

Thanks for the swift reply, Isdoo.

I've tried your suggestion - including limiting the number of characters - but the same thing is happening.

I actually think that the feed isn't accessing the updated version of the rss.xml.php file. I compacted the code in this file now there isn't a line 22, which is where it says the error is.

I tried deleting this file from the server but the same error message appears, whereas I would have expected a message that tells me the feed can't be read.
Nigel Gordijk

Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net

Re: [NigelGordijk] RSS feed error message/Headlines from multiple sections

By isdoo - July 17, 2009

certainly looking at your rss feed, I can't see a summary or content, so it certainly looks like the line...

<description><?php echo htmlspecialchars($record['summary']); ?></description>

is at fault. If your field is called summary, then I can't see where the issue might lie, especially as the other fields are working.

Re: [isdoo] RSS feed error message/Headlines from multiple sections

Actually, this line should read:

<description><?php echo htmlspecialchars($record['introduction']); ?></description>

I've corrected the name error - thanks for pointing that out - but still no joy.
Nigel Gordijk

Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net

Re: [NigelGordijk] RSS feed error message/Headlines from multiple sections

By isdoo - July 17, 2009

I can't see a style now for your page at http://www.yallaf1.com/rss.xml.php - but I can see a desciption now :)

Re: [NigelGordijk] RSS feed error message/Headlines from multiple sections

By ross - July 17, 2009 - edited: July 17, 2009

Hi Nigel

You should be able to get one list of records from two different sections in CMS Builder. The way I would do is stick the viewer code for both sections at the top of your page. This will give you one array of records for each section.

You would then need to combine those sections (there's a php function for that) and then voila. One list of records that's actually comprised from two sections.

Let me know if that makes sense. Can I go over the code in some more detail for you? It's probably going to get a little advanced. The best place to start would be if you could just set me up a test.php page with the viewers for both sections you want to combine in it. Just post that as an attachment.

Thanks!
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] RSS feed error message/Headlines from multiple sections

Hi, Ross.

Thanks for your reply.

Creating one list from two sets of data isn't a problem for me; it's creating a single list that is chronological based on the order that the content was added, regardless of which section it is taken from.

For example, say the list is made up of five headlines that is made up of the five most recent articles in the Top Stories and Daily News sections. It might be that the headline at the top of the list comes from Daily News because that was the article that was added most recently. The second might be from Top Stories because it was the second most recent, and so on.

Does that description make sense? I'm not trying to have, say, all of the most recent Top Stories' headlines followed by all of the ones for Daily News. We'd like them to be mixed up, if possible.

Kind regards,
Nigel Gordijk

Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net

Re: [NigelGordijk] RSS feed error message/Headlines from multiple sections

By ross - July 23, 2009

Hi Nigel

That makes sense. This one ended up being a little trickier than expected but I do have some code you can try out:

<?php $mergedArray = array_merge($news1Records, $news2Records, $news3Records); ?>
<?php

uasort($mergedArray, '_sortByDate');
function _sortByDate($recordA, $recordB) {
return strcmp($recordA['createdDate'], $recordB['createdDate']);
}

?>

<?php foreach ($mergedArray as $record): ?>
<?php echo $record['createdDate']; ?> - <?php echo $record['title']; ?><br/>
<?php endforeach ?>


The first line you just need to swap in your arrays, then in the foreach loop, you can swap in the approriate fields. I have it displaying the created date and title.

This will sort your list based on when each item was created.

Give this a shot and let me know how you make out :).
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/