Skip to content

Instantly share code, notes, and snippets.

@jkishner
Created August 14, 2013 21:50
Show Gist options
  • Save jkishner/6236023 to your computer and use it in GitHub Desktop.
Save jkishner/6236023 to your computer and use it in GitHub Desktop.
post an opml file as an unordered list in a wordpress post or page. just use the shortcode [opml url="OPML_URL"] in the content area. This is based on a php script by Betsy Kimak http://www.umaitech.com/cms/?p=311
<?php
/*
Plugin Name: OPML in WordPress
Author: Jeffrey Kishner
*/
function fargo2opml ($opmlfile) {
$opmfile = shortcode_atts(array(
'url' => '',
), $opmlfile);
function parse_opml($xml,$depth=1) {
if (count($xml->children()) > 0) {
echo'<ul>';
}
foreach ($xml->children() as $child) {
if ($child['url']) {
echo '<li><a href='.$child['url'].'>'.$child['text'].'</a></li>';
}
else {
echo '<li>'.$child['text'].'</li>'; // level 1 outlines
}
parse_opml($child,$depth+1); // nested outlines
}
if (count($xml->children()) > 0) {
echo '</ul>';
}
}
$file = new SimpleXMLElement($opmlfile['url'],null,true);
echo '<h4>' . $file->head->title . '</h4>';
parse_opml($file->body);
}
add_shortcode('opml', 'fargo2opml');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment