On Sun, 20 Jul 2003 12:28:55 +0200, [EMAIL PROTECTED] (Merlin) wrote: >Hi there, > >I was searching on the net for a while on how to create dynamic newsfeeds >from my web portal. Somehow I did not find what I was looking for. > >Can anybody give me a good start on how to write a newsfeed service which is >dynamic? The goal is whenever a member publishes a story on the site, it >should be included into the newsfeed. > >Thanx for any suggestions and help on this!
Two ways of doing it, basically. First is a dynamic PHP page that goes though the last ten or whatever updates and displays them as RSS (in much the same way you display a "recent articles" page, except you output XML instead of HTML) Second is to create the page as above whenever you add a new story and then output it to a static file. Output of RSS is fairly simple, start off with <?PHP header("content-type: text/xml") ?> then build up the introductory data (I'm using a stripped down version of my own feed as an example here): <example> <?xml version="1.0" encoding="utf-8"?> <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"> <channel> <title>Aquarionics</title> <link>http://www.aquarionics.com</link> <description></description> <dc:language>en-gb</dc:language> <dc:creator>Aquarion ([EMAIL PROTECTED])</dc:creator> <dc:rights>Copyright 2003 Aquarion</dc:rights> <dc:date>2003-07-20T11:55:00+0100</dc:date> <admin:generatorAgent rdf:resource="http://www.aquarionics.com/epistula/?v=2.0.2b" /> <admin:errorReportsTo rdf:resource="mailto:[EMAIL PROTECTED]"/> <sy:updatePeriod>daily</sy:updatePeriod> <sy:updateFrequency>8</sy:updateFrequency> <sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase> </example> If it's a database, query for the last 10 items, then loop though them and output the code: <item> <title>Journal - Aquarion and the Missing Domain</title> <link>http://www.aquarionics.com/journal/2003/07/18/Aquarion_and_the_Missing_Domain</link> <comments>http://www.aquarionics.com/journal/2003/07/18/Aquarion_and_the_Missing_Domain</comments> <description>In which a server vanishes</description> <guid isPermaLink="true">http://www.aquarionics.com/journal/2003/07/18/Aquarion_and_the_Missing_Domain</guid> <content:encoded><![CDATA[ <p>Okay, so in the confusion of yesterday, I forgot to mention something. As of yesterday morning, the entire gkhs.net network went <span class="caps">AWOL</span> because for some reason neither of the people who have the domain got any emails reminding us that it was due to expire.</p> <p>This is why none of you have discovered that spirit.gkhs.net isn’t working for <span class="caps">IRC</span> atm. I’ll relaunch it when I get them back again (I’ve now renewed the domain).</p> ]]></content:encoded> <dc:date>2003-07-18T07:33:00+0100</dc:date> <dc:subject>computing</dc:subject> </item> Finally, do the final closing tags: </channel> </rss> and then run it though the Feed Validator at http://feeds.archive.org/validator/ to make sure you haven't done anything silly :-) The specification for RSS2 (which will tell you - or help you - know what goes in all the tags I used above) is at http://blogs.law.harvard.edu/tech/rss HTH -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php