Created
December 6, 2012 00:10
-
-
Save vilmosioo/4220761 to your computer and use it in GitHub Desktop.
Create your own Tumbleblog in WordPress! Example usage with my feeds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // Get RSS Feed(s) | |
include_once(ABSPATH . WPINC . '/feed.php'); | |
$feed = array(); | |
$feed += add('http://vilmosioo.co.uk/feed/', 'wp'); | |
$feed += add('http://pinterest.com/ioowilly/feed.rss', 'pinterest'); | |
$feed += add('http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=ioowilly', 'twitter'); | |
$feed += add('http://www.goodreads.com/user/updates_rss/4165963?key=a5d32462cef6d00b08e095ba9b74d3e03c310841', 'goodreads'); | |
krsort($feed); | |
echo '<pre>'; | |
//print_r($feed); | |
echo '</pre>'; | |
foreach($feed as $item){ | |
switch ($item['type']) { | |
case 'wp': | |
echo "<article class='tumblog-item wordpress'><a href='".$item['link']."' class='icon wordpress'></a><h3><a href='".$item['link']."'>".$item['title'].'</a></h3><p>'.strip_tags($item['description']).'</p></article>'; | |
break; | |
case 'twitter': | |
echo "<article class='tumblog-item twitter'><a href='".$item['link']."' class='icon twitter'></a>".substr($item['title'], 9).'</article>'; | |
break; | |
case 'pinterest': | |
echo "<article class='tumblog-item pinterest'><a href='".$item['link']."' class='icon pinterest'></a>".$item['description']."<div class='clear'></div></article>"; | |
break; | |
case 'goodreads': | |
if( $item[description] != '' ) | |
echo "<article class='tumblog-item goodreads'><a href='".$item['link']."' class='icon goodreads'></a>".$item['description']."<div class='clear'></div></article>"; | |
break; | |
} | |
} | |
function add($url, $type){ | |
// Get a SimplePie feed object from the specified feed source. | |
$rss = fetch_feed($url); // specify the source feed | |
$rss->set_cache_duration(1); | |
switch ($type) { | |
case 'pinterest': $no = 5; break; | |
case 'goodreads': $no = 5; break; | |
default: $no = 15; | |
} | |
if (!is_wp_error( $rss ) ) : // Checks that the object is created correctly | |
// Figure out how many total items there are, but limit it to 5. | |
$maxitems = $rss->get_item_quantity($no); | |
// Build an array of all the items, starting with element 0 (first element). | |
$rss_items = $rss->get_items(0, $maxitems); | |
endif; | |
if ($maxitems == 0) { | |
echo '<li>There are no items to show for '.$url.'.</li><pre>'; | |
print_r($rss); | |
echo '</pre>'; | |
} else { | |
// Loop through each feed item and display each item as a hyperlink. | |
foreach ( $rss_items as $item ) : | |
$wp = array('type' => $type); | |
$wp['time'] = strtotime($item->get_date()); | |
$wp['link'] = $item->get_link(); | |
$wp['description'] = $item->get_description(); | |
$wp['title'] = $item->get_title(); | |
$feed[ $wp['time'] ] = $wp; | |
endforeach; | |
} | |
return $feed; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment