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 thumb17 Link to your latest Blog entry, automatically

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://www.tomschaefer.org/web/wordpress/?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.

  • Share/Bookmark
This entry was posted in Web Design. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. Posted February 16, 2009 at 09:56 | Permalink

    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. Posted February 13, 2010 at 02:41 | Permalink

    I consider, that you are mistaken. I can defend the position. pill vagra buy online Sorry, for off top, i wanna tell one joke) Why are there so many Johnsons in the phone book? They all have phones.

One Trackback

  1. [...] the original post: Link to your latest Blog entry, automatically Related ArticlesBookmarksTags How to Automatically Capitalize a String in PHP PHP, one of [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*
  • Welcome to TomSchaefer.org