Include an Evernote feed in your WordPress blog

I use Evernote to keep track of my ToDo’s, interesting web pages that I visited, found code snippets or some random thoughts. I have it configured in a browser on my laptop and as a separate app on my smartphone.

“Things” in Evernote are put in notebooks, notebooks can be shared. I’ve been sharing some of my notebooks with friends and colleagues to keep track of joint projects. These shared notebooks have a RSS feed. You can include this feed wherever you want : your favorite news reader or on your own web site.

The snippet below shows that it is fairly easy to accomplish this in WordPress. Unfortunately (as far as I can tell), you can not retrieve the tags of the notes in the RSS feed.
You’ll have to include the snippet somewhere in your WordPress custom theme. I have it in sidebar.php.

The code is also available at Github https://github.com/cudeso/tools.

// When you are changing your theme, the retrieved feed will be cached. You can prevent caching with limiting the lifetime. 
// Don't use this in a production environment!!
/*
function return_1( $seconds ) {
  return 1;
}
add_filter( 'wp_feed_cache_transient_lifetime' , return_1);
*/

// Limit the number of items to retrieve
$maxitems_feed = 10;
$feed_url = "http://www.evernote.com/_whatever_links_to_your_feed/rss.jsp";
$rss = fetch_feed($feed_url . "?max=" . $maxitems_feed . "&sort=2");

if (!is_wp_error( $rss ) ) : // Checks that the object is created correctly 
    // Figure out how many total items there are, but limit it to maxitems_feed. 
    $maxitems = $rss->get_item_quantity($maxitems_feed); 
    // Build an array of all the items, starting with element 0 (first element).
    $rss_items = $rss->get_items(0, $maxitems); 
endif;

if (!($maxitems == 0)) {
	?><h1><?php _e( 'Evernote Feed' ); ?></h1>
	<ul>
	<?php
	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'); ?>'>
			        <?php echo esc_html( $item->get_title() ); ?></a>
		</li>
		<?php
	}
	?>
	</ul>
	<?php
}

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.