RSS Feed Setup

12 posts by 4 authors in: Forums > CMS Builder
Last Post: September 3, 2009   (RSS)

By InfamousNugz - July 27, 2009 - edited: July 27, 2009

Interactive Tools,
I am attempting to install an RSS feed that automatically updates the content via what they post in the CMS builder. What I am using seems to work if I put just text in but when I enter the PHP nothing shows other than the main sections.

*FIXED*

Re: [InfamousNugz] RSS Feed Setup

By Dave - July 27, 2009

Hi InfamousNugz,

Can you post the url to the rss feed so I can take a look?

Also I think this code needs to be removed (in red):
<?php echo $record['headline'], 75 ?>

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] RSS Feed Setup

By InfamousNugz - July 27, 2009 - edited: July 27, 2009

Sorry that was from reading a previous entry and trying to get it to work. I tried it in both XML and PHP which can be found at the below links. Putting it php got the title to show but not the headline or link. Thank you for your help.

Re: [InfamousNugz] RSS Feed Setup

By Dave - July 27, 2009

You can validate your feed here to see any errors:
http://validator.w3.org/feed/check.cgi?url=http://www.959watd.com/test.php

The first error seems to be related to the tags in the content. You can remove those like this:

<?php echo strip_tags( $record['headline'] ); ?>

Or try encoding them like this:
<?php echo htmlspecialchars( $record['headline'] ); ?>

Next, it looks like for you links you need to add the full url such as:
<link>http://www.959watd.com/<?php echo $record['_link'] ?></link>

Give that a try and let me know how it goes.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] RSS Feed Setup

Thanks that worked!

Re: [Dave] RSS Feed Setup

Hi, Dave.

I'm using the following code on a client's site, which is working fine:

<?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['introduction']); ?></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 ?>

The client wants to also include the first 250 characters from the main text of the article. Can you tell me how to do this, please?

This is the article code:

<?php echo $top_storiesRecord['content'] ?>

Kind regards,
Nigel Gordijk

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

Re: [NigelGordijk] RSS Feed Setup

By Chris - September 2, 2009 - edited: September 2, 2009

Hi Nigel,

You can clip a string with the substr() PHP function. For example:

<?php
echo substr($top_storiesRecord['content'], 0, 250);
?>


In the case that the string is shorter than 250 characters, the entire string will be returned intact. Of course, you might want something that adds "..." to the end of the string if you were forced to clip it:

<?php
$text = $top_storiesRecord['content'];
if (strlen($text) > 247):
$text = substr($text, 0, 247) . "...";
endif;
echo $text;
?>


Of course, that code might clip in the middle of a word (eg. "like thi..."), so I got carried away and wrote a regexp to clip at a word boundary. This code may output less than 250 characters, but will never output more:

<?php
$text = $top_storiesRecord['content'];
if (strlen($text) > 247):
$minCharsToRemove = strlen($text) - 247;
$text = preg_replace('/^(.*\S)\b.*?.{'.$minCharsToRemove.'}$/s', '\\1', $text) . "...";
endif;
echo $text;
?>


Hope this helps! (and works!) :)
All the best,
Chris

Re: [NigelGordijk] RSS Feed Setup

By Chris - September 2, 2009

Hi Nigel,

Hmm. You seem to already be populating the <description> tag with a field called "introduction", but the field you said you wanted to add part of is called "content". Did your client want the "content" field appended to the "introduction"?
All the best,
Chris

Re: [chris] RSS Feed Setup

Sorry, that should say "content", not "introduction".
Nigel Gordijk

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