Thursday, July 31, 2008

Rendering Blog Content to a web page

I received an email last night asking about how we render the table of contents from our blog to our home page. I thought this would make a good blog entry itself, so here it is.

Our home page is an Active FoxPro (AFP) page. It contains the code below to render the blog.

Someone just pointed out to me that this code wasn't showing up under ie. Bad ie!

Blogfeed is a function I have defined in the .AFPA.Code file for I've attached the relevant code in a program named blogfeed in a zip file here.

In a nutshell the blogfeed class uses the Microsoft.XMLHTTP COM object to retrieve the URL, creates a cursor from it, locates the first record we want to render and then spits it out into an HTML table. I've used various versions of this class for a number of different blogs. The structure of the cursor created from the XMLToCursor call can vary widely and which record you want to start on will also vary, but this should be pretty easy to tweak to deal with that.

The id=DTOS(DATETIME()) parameter I'm appending to the URL is a dummy parameter. Feedburner doesn't do anything with this parameter, but I had to append something to force a new read. Without adding this the server (or something at feedburner maybe) seemed to cache the feed and it would take several days before new blog entries would show up. Using a GUID or a SYS(2015) value might be a better approach since those values would change on each call, but for my purposes, I don't mind if the feed is cached once a day because this should take a load off the server.

The BlogFeed wrapper function is designed for simple calls. The blogfeed class has a number of properties that are designed to make it possible to work with different blogs, use different styles and so on. Below are the key properties and methods you'll use to customize the blogfeed class for other content.

  • cBlogURL - The URL for the blog
  • cAlias - The alias created when the blog is loaded into a cursor.
  • nMaxEntries - The maximum number of blog entries to render.
  • nMaxNew - The maximum number of entries to flag as new. This property can be set to zero to specify no entries should be flagged as new.
  • nNewDays- The number of days to consider an item new.
  • cTitleField - The name of the field that contains the title for the blog entry.
  • cURLField - The name of the field that contains the URL for the blog entry.
  • cNewStyle - The style to use for items flagged as new.
  • cArticleStyle - The style to use for links to articles.
  • cErrorMessage - The error message to display when the blog cannot be read.

  • Render - Renders the blog as HTML
  • FindFirstEntry - Finds the first record to be written to the HTML table. Most blog feeds will create some header records that should be ignored.
  • GetEntryDate - Returns the date of a blog entry. Most feeds will contain a field that contains the date of the blog entry, but the format may vary greatly. This method typically is overridden to parse the date from this field.
The blogfeed class is a really simple class to make use of. I'm using AFP. The syntax for Web Connection should be identical. If you're using another web technology it should be fairly easy to adjust the call to the blog feed function as necessary. Enjoy! Somewhere around here I have calls for the VFP Wiki, VFPX, FoxCentral and a few other fox centric sites. I plan on deploying them all to a single page as a generic VFP portal sometime soon.

Labels: , ,


Post a Comment

<< Home