Link to your latest Blog entry, automatically

or link to any RSS Links via PHP.

On my home page I have a section near the bottom that has a link to my latest blog entry. This didn’t use to be automatic for me. I used to manually edit every link and title to my latest blog entry to keep that link accurate. That gets boring and really old after a while, why not make it automatic.

I tried to do it via SQL but could never get it to work the right way. Well there are many solutions out there. If you can run PHP files than its even easier via Magpie’s RSS Parser.

Download the parser and create a directory on your server that contains the following files:

  • rss_cache.inc
  • rss_fetch.inc
  • rss_parse.inc
  • rss_utils.inc
  • extlib/Snoopy.class.incimage

That’s all you need. Notice extlib is a directory containing Snoopy.class.inc.

Now create a PHP file that includes the rss_fetch.inc. Examples are available on Magpie’s Page. MagpieRSS is compatible with RSS 0.9 through RSS 1.0. Also parses RSS 1.0’s modules, RSS 2.0, and Atom. (with a few exceptions)

<?php
require_once ‘rss_fetch.inc’;

$url = ‘http://cyberredneck.org//?feed=rss2‘;
$rss = fetch_rss($url);

//echo “Site: “, $rss->channel[‘title’], “<br>”;
$item = $rss->items[0];
$title = $item[title];
$url   = $item[link];
echo “<a target=_blank href=$url>$title</a></li><br>”;
?>

This PHP code will parse my RSS Feed, grab the top entry and produce a link that opens in a new page. For optimum stability I always suggest using relative links, absolute links can fail especially if you have multiple domains like I do.

5 Replies to “Link to your latest Blog entry, automatically”

  1. Cool man. I cant get to your site with Google Chrome. It just stays at the loading… screen. Let me know if my shit is jacked or if you have problems with it too!

  2. Great blog! Is your theme custom made or did you download it from somewhere?
    A design like yours with a few simple tweeks would really make my blog stand out.
    Please let me know where you got your design. Many thanks

  3. Excellent post. I used to be checking continuously this blog and I’m inspired! Extremely helpful info specially the last part 🙂 I take care of such info a lot. I used to be seeking this certain info for a very long time. Thanks and good luck.

Leave a Reply

Your email address will not be published. Required fields are marked *