News feeds in a static page

News feeds in a static page

This is a simple way to include news feeds in a static page, if you don't want to mess around with My Headlines and other plugins, but just want to add one (or more) cached feeds to a page. All you need is one file in your geeklog system directory, or wherever you like, and five lines of code.

global $_CONF;
include( $_CONF['path_system'] . "/lib-rss.php" );

$file = "test.rdf";
$feed = "http://news.bbc.co.uk/rss/newsonline_world_edition/science/nature/rss091.xml";
$time = time() - 3600;

print staticpageRSS ( $file, $feed, $time );

How to do it

  1. Upload the file lib-rss.php to your geeklog system directory with the other lib- files. Get the archived file here.
  2. Set your static page to "execute PHP" (the third of the three options) and paste in the text in the box above.
  3. Change the include path to show where you placed the file lib-rss.php if you did not put it in the system folder.
  4. Set $file to the name of the file to use a cache for this feed. The file wiil be stored in your backend directory.
  5. Set $feed to the feed you want to read from.
  6. Change the amount subtracted from time() to determine how often you want the cache to be refreshed. The amount deducted is in seconds, so the default 3600 is 3600 seconds, or one hour.

Caveats

The first time you open a feed, you will get an error as the file does not exist yet. Just refresh the page. If that doesn't work, you may need to create the file yourself.

Modifications

If you open the file lib-rss.php, you will see that the first function is what calls the other code and determines where the cache is saved, and the format of the returned page. You can easily edit this to suit your tastes.

This has not been heavily tested, so please let me know if you have any problems.

Credits

lib-rss.php contains another file that does all the real work.

|