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
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
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']
Hope that helps!
interactivetools.com
Re: [Dave] RSS Feed Setup
By InfamousNugz - July 27, 2009 - edited: July 27, 2009
Re: [InfamousNugz] RSS Feed Setup
By Dave - July 27, 2009
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.
interactivetools.com
Re: [Dave] RSS Feed Setup
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,
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
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!) :)
Chris
Re: [chris] RSS Feed Setup
If this is my code now, where should your new code go?
<?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 ?>
Kind regards,
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
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"?
Chris
Re: [chris] RSS Feed Setup
Common Sense Design: User-focused Web design
Tel: 001 519 342 5348 | Web: www.commonsensedesign.net