Quick Umbraco tip: Display twitter feeds on your site

First, install the Ferguson Moriyama Feed Cache package for Umbraco. Make sure you read the install instructions which explain how to get the package to run as a scheduled task.

Grab the URL for your twitter feed, mine is http://search.twitter.com/search.atom?lang=en&q=from%3Adarrenferguson. You can turn any twitter search into an atom feed by visiting search.twitter.com and clicking on the ‘Feed for this query’ button after your search.

Next, configure the Feed Cache package to cache your feed. Open <webroot>/umbraco/plugins/FergusonMoriyama/FeedCache/feeds.config and add an entry like the following:

<?xml version="1.0"?>

Wait a little while until twit.xml appears in the <webroot>/umbraco/plugins/FergusonMoriyama/FeedCache folder. If it doesn’t there is probably something wrong with your scheduled task setup.

Use the following XSLT macro to display tweets on your site:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:Stylesheet [<!ENTITY nbsp "&#x00A0;">]>
 exclude-result-prefixes="msxml umbraco.library Atom"
    <xsl:variable name="y" select="document('../umbraco/plugins/FergusonMoriyama/FeedCache/twit.xml')/Atom:feed"/>
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>
    <xsl:template match="/">
        <xsl:for-each select="$y/Atom:entry">
                    <xsl:value-of select="umbraco.library:FormatDateTime(Atom:published, 'MMMM d, yyyy @ H:mm')"/>
		<xsl:value-of select="Atom:content" disable-output-escaping="yes"/>

Obviously you can just change your twitter search to look for hash tags, Umbraco related tweets or whatever you want. There is also a lot more information in the atom feed than I am displaying above and the XLST can be modified to your liking.


Leave a comment