Created
July 16, 2011 12:36
-
-
Save kovshenin/1086313 to your computer and use it in GitHub Desktop.
WordPress Dashboard Feed Reader
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 | |
add_action( 'wp_dashboard_setup', 'my_dashboard_setup' ); | |
function my_dashboard_setup() { | |
wp_add_dashboard_widget('themefm-dashboard-reader', 'Latest from Theme.fm' , 'my_dashboard_content', $control_callback = null); | |
} | |
function my_dashboard_content() { | |
echo "<p>Dashboard Widget Content</p>"; | |
} |
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 | |
$feed = fetch_feed( 'http://theme.fm/feed/' ); | |
print_r( $feed ); |
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 | |
function my_dashboard_content() { | |
$feed = fetch_feed( 'http://theme.fm/feed/' ); | |
if ( ! is_wp_error( $feed) ): | |
// Get a maximum of 5 items | |
$maxitems = $feed->get_item_quantity( 5 ); | |
$items = $feed->get_items( 0, $maxitems ); | |
foreach ( $items as $item ): | |
?> | |
<p class="rss-widget"> | |
<a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a> <span class="rss-date"><?php echo $item->get_date( 'F j, Y' ); ?></span><br /> | |
<?php echo $item->get_description(); ?> | |
</p> | |
<?php | |
endforeach; | |
else: // Returned WP_Error, unable to fetch the feed. | |
?> | |
<p>There was an error fetching the Theme.fm feed, please try again later</p> | |
<?php | |
endif; | |
?> | |
<p class="description">— Read more on <a href="http://theme.fm">Theme.fm</a></p> | |
<?php | |
} |
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 | |
// Don't duplicate the dashboard widget, only activate if hasn't | |
// been activated by another theme or plugin. | |
if ( ! defined( 'THEMEFM_DASHBOARD_READER_ACTIVE' ) ) | |
add_action( 'admin_init', create_function( '', 'global $themefm_dashboard_reader; $themefm_dashboard_reader = new Themefm_Dashboard_Reader();' ) ); | |
define( 'THEMEFM_DASHBOARD_READER_ACTIVE', true ); |
Ramoonus, because they're embedded separately in the tutorial on Inspired Magazine :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
why are there 4 files?