code » xfn_blogroll_retag v0.1
29 March 2005
Introduction
Bloglines, my favoured RSS reader service, has a facility that lets you embed your blogroll into your blog or other site.
On converting to WordPress 1.5, I noticed that there it included references to XFN tagging, a protocol that lets you specify your relationship to the person denoted by a particular link, and thus build up a network of friends, lovers, muses and so on. I liked the idea of this, but found that I had very few links that would qualify apart from on my blogroll.
I wasn't going to change the system I used to read blogs so I decided to hack things about a bit and produce some PHP that would let me add the appropriate tags to my links.
The code
xfn_blogroll_retag() is a function that needs to be run from within existing PHP, and it is as follows...
Usage
The flat XFN file
How does the function know what your relationships are with your linkees? It's not psychic, it needs to read in a flat text file that you have to make and save somewhere. This is not, however, difficult. Each line specifies a particular linkee, and is in the format:
(URL of blog) (tab) (XFN code)
For instance, a sample might be:
http://mudshow.blogspot.com acquaintance met
http://www.urban75.org/blog.html acquaintance met
http://keroseneoysterhell.blogspot.com acquaintance met
http://yuptrenton.typepad.com/quick_story/ acquaintance met
You will probably want to have the quick guide to XFN codes open while you do this, but there aren't many of them to remember. You could also check the rel parameters produced by the XFN Creator.
So get out your text editor. If you're really lazy you can use this page to generate the appropriate text. Save the file somewhere you can find it again.
Embedding the function
The function xfn_blogroll_retag needs to be included in your PHP somewhere, either pasted into it or held in another file and referred to with include().
xfn_blogroll_retag takes three arguments. The first is the location of the text to retag, and is required. (You should know this already - if you don't, what are you doing here?) The second is the location of the flat file to retag with that you created earlier, and is also required. The last is the URL of an image to use as an icon indicating that that link has XFN information. If this is not present, no image will appear. I use the mini xfn icon that you can see below.
Here is a sample embed:
<?php
include('tools/xfn_blogroll_retag.php');
xfn_blogroll_retag('http://rpc.bloglines.com/blogroll?html=1&id=fridgemagnet&folder=Blogs',
'tools/bloglines_xfn.txt', '/images/icons/xfn-mini.gif');
?>
tools/xfn_blogroll_retag.php just contains the function and nothing else.
Styling
I have the following:
img.xfn { float: right; cursor: help; }
in my stylesheet, which positions the button and changes the cursor to the help icon. Roll the mouse over
and you should see the cursor change, and a title appear.
Comments
If you've got any comments, leave them on the related blog entry.