Automatically updating a WordPress blogroll

Years ago, I signed up to a social bookmarking system called Spurl. I’m really not interested in social bookmarking, but it had a handy feature: by inserting a bit of Javascript in a web page, you could pull all or a subset of the links out and display them in a list. That meant that I could add links to my blogrolls by simply bookmarking a link using Spurl, and categorising it. No need to fiddle around going to the blog admin and adding the link. It was really useful for easily sharing links and maintaining links pages.

Sadly, Spurl was overwhelmed by spam and disappeared. After that I bumbled around trying to find another service that provided the same functionality. It seemed obvious that lots of people would want this. But no. I managed to get something similar working with Furl.net. But then that was taken over by Diigo (a problem with these services is that they keep disappearing or being taken over). Diigo claimed I could do the same thing, but no matter what I did, it refused to show more than the 3 newest links in a particular category. Not very useful for a blogroll (although I do use it for recent links here — see the sidebar on the home page). Del.icio.us doesn’t seem to have any functionality like this.

Yesterday, while half-heartedly trying to resolve this problem, I happened across Sitebar. Yes, another bookmark manager. But this one is open source, and you can install it on your own server. Complete control! Hastily I installed it (a 5-minute job). Added a few bookmarks and experimented with the RSS feed. Once I’d figured that out, some googling and digging in the WordPress codex came up with a way to get WordPress to read the RSS feed and display it in the sidebar.

<div id="sitebar_linkroll" >
<?php
// Get RSS Feed(s)
include_once(ABSPATH . WPINC . '/feed.php');
// Get a SimplePie feed object from the specified feed source.
$rss = fetch_feed('http://www.archetype-it.com/sitebar/index.php?hits=0&w=rss&mix=nodes&root=16');
if (!is_wp_error( $rss ) ) : // Checks that the object is created correctly
// Figure out how many total items there are, but limit it to 20.
$maxitems = $rss->get_item_quantity(20);
// Build an array of all the items, starting with element 0 (first element).
$rss_items = $rss->get_items(0, $maxitems);
endif;
?>

<ul>
<?php if ($maxitems == 0) echo '<li>No items.</li>';
else
// Loop through each feed item and display each item as a hyperlink.
foreach ( $rss_items as $item ) : ?>
<li>
<a href='<?php echo esc_url( $item->get_permalink() ); ?>'
title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'>
<?php echo esc_html( $item->get_title() ); ?></a>
</li>
<?php endforeach; ?>
</ul>
</div>

Ta-dah! This may seem a bit overkill for a blogroll, but it solves a problem for me. And Sitebar is a nice links manager in itself, even if it looks a little old-fashioned (no trendy tags, just folders!) and hasn’t been updated since 2007. There is a hosted version with free and paid options, but hosting it myself means I don’t need to worry about the service disappearing or changing its terms, and if it does what I want it doesn’t really matter if it’s not being actively maintained. It’s designed to be used in the panel/sidebar area of a browser, hence the name. So I’ve added it to Opera as a panel, where it’s easily accessible for adding links (there’s a Javascript bookmarklet too, for one-click adding, though I haven’t got that working in Opera yet).

Note, of course, that you can use this same PHP code for any RSS feed that you want to incorporate into a WordPress site — just edit the feed URL.

This entry was posted in Blogging, PHP, Web development, Wordpress and tagged , , . Bookmark the permalink.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>