I want an RSS Feed for latest post on my forum (sparked by Cemetech's latest post feed). I know that I don't have any members but I would still like to add an automated RSS feed for fun.
can anyone help me out please?
All you need is to learn the proper XML for an RSS feed, then generate it with some PHP.
I understand xml, but could I see the php that you use to generate it? I'm guessing that it will be extremely similar to what i would need.
It's really not that complicated. Just have it pull out the latest topic subject... stick it on the RSS subject line, etc. etc. You can either loop it until you have the desired number of items, or if you don't know how just hardcode each individual news item.
Here you go. Actually, the more I look at this, I see a lot of optimizations to be made. I wrote this before I totally understood SQL. Razz


Code:
<?php
[Mysql connection code removed for security purposes]
$sql = "SELECT * FROM table_articles";
if ( !($result = $mdb->sql_query($sql)) )
{
   echo 'DB Access Error!<BR>';
   exit;
}
$totallines = mysql_num_rows($result);

header('Content-type: text/xml');
print('<?xml version="1.0" encoding="iso-8859-1" ?>');
print('<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:annotate="http://purl.org/rss/1.0/modules/annotate/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<!--
   This feed generated for Cemetech by CemetechNews
-->
<channel>
<title>Cemetech</title>
<link>http://www.cemetech.net/</link>
<description>Leading the Way to the Future</description>
<managingEditor>kerm_martian@yahoo.com</managingEditor>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<generator>RSS Feed 2.2.1</generator>
<language>en</language>
<lastBuildDate>');
echo date('D, d M Y H:i:s') . ' CST';
print('</lastBuildDate>
<image>
   <url>http://www.cemetech.net/img/logo/cemetech.gif</url>
   <title>Cemetech</title>
   <link>http://www.cemetech.net/</link>
   <width>236</width>
   <height>37</height>
</image>');
$count = 0;
$sql = "SELECT * FROM table_articles";
if ( !($result = $mdb->sql_query($sql)) )
{
   echo 'DB Access Error!<BR>';
   exit;
}
while (($count != 4) && ($row = $mdb->sql_fetchrow($result))) {
   $newsID = $row['newsID'];
   Display_Article($row['title'],$row['timestamp'],$row['discusslink'],$row['text'],"http://www.cemetech.net/news.shtml?$newsID");
   //Display_Article($curnewsarray[0],$curnewsarray[1],$curnewsarray[2],$curnewsarray[3],"http://www.cemetech.net/news.shtml?$numlink");
   $count++;
}
print('</channel></rss>');
exit;
function Display_Article($atitle,$adate,$adiscusslink,$atext,$apermlink)
{
print('<item><title>');
$atitle = xmlclip($atitle);
print($atitle);
print('</title><link>');
$apermlink = xmlclip($apermlink);
print($apermlink);
print('</link>');
print('<pubDate>');
$adate = sqltotime($adate);
$adate = date('D, d M Y H:i:s',$adate) . ' CST';
$adate = xmlclip($adate);
print($adate);
print('</pubDate>');
print('<guid isPermaLink="true">');
print($apermlink);
print('</guid><description>');
$atext = xmlclip($atext);
print($atext);
print('</description><dc:creator>Kerm Martian</dc:creator><dc:subject>');
print($atitle);
print('</dc:subject></item>');
}
function xmlclip($a) {
$a = str_replace('&','&amp;',$a);
$a = str_replace('"','&quot;',$a);
$a = str_replace('<','&lt;',$a);
$a = str_replace('>','&gt;',$a);
$a = str_replace('&nbsp;',' ',$a);
$a = str_replace('&nbsp',' ',$a);
return $a;
}
function sqltotime($a)
{
    $year = substr($a, 0, 4);
    $month = substr($a, 5, 2);
    $day = substr($a, 8, 2);
    return mktime(0, 0, 0, $month, $day, $year);
}
?>
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement