Quick-&-Dirty Delicious Feeds for Wordpress
After looking around at the available Delicious plugins for Wordpress, I found two functioning ones, both of which that used and had broken tag support.
Ho hum.
Here’s what I used in a pinch; this’ll be turned into a Wordpress plugin with an interface to match the existing Delicious-for-Wordpress plugin. Until that happens:
// TODO: Make plugin, add count, feed and caching configurability.
$delicious_rss = 'http://feeds.delicious.com/v2/rss/damncabbage';
$delicious_item_count = 9;
$encoding = 'utf-8';
$feed = fetch_feed($delicious_rss);
$limit = $feed->get_item_quantity($delicious_item_count);
$items = $feed->get_items(0, $limit);
if ($limit == 0) {
?><li>No delicious for you today.</li><?php
} else {
foreach ($items as $item) {
$link = htmlentities($item->get_permalink(), ENT_QUOTES, $encoding);
$title = htmlentities($item->get_title(), ENT_QUOTES, $encoding);
$tags = $item->get_categories();
?>
<li>
<p class="link"><a href="<?php echo $link; ?>"><?php echo $title; ?></a></p>
<p class="tags metadata"><?php
$tag_links = Array();
foreach ($tags as $tag) {
$term = htmlentities($tag->term, ENT_QUOTES, $encoding);
$url = htmlentities($tag->scheme.$tag->term, ENT_QUOTES, $encoding);
$tag_links[] = '<a href="'.$url.'">'.$term.'</a>';
}
echo implode(', ', $tag_links);
?></p>
</li>
<?php
}//end foreach (items)
}//end else (items)
Default caching. Markup mixed with data retrieval. Not pretty.
Expect this one to be pluginified in a couple of days.
Posted January 14th, 2010 | No Comments