Add sports news widget
This commit is contained in:
@@ -31,6 +31,7 @@ class SP_Admin_Dashboard {
|
||||
* Init dashboard widgets
|
||||
*/
|
||||
public function init() {
|
||||
wp_add_dashboard_widget( 'sportspress_dashboard_news', __( 'Sports News', 'sportspress' ), array( $this, 'news_widget' ), null, null, 'side' );
|
||||
wp_add_dashboard_widget( 'sportspress_dashboard_status', __( 'SportsPress', 'sportspress' ), array( $this, 'status_widget' ) );
|
||||
add_filter( 'dashboard_glance_items', array( $this, 'glance_items' ), 10, 1 );
|
||||
}
|
||||
@@ -95,6 +96,30 @@ class SP_Admin_Dashboard {
|
||||
</ul>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Show news widget
|
||||
*/
|
||||
public function news_widget() {
|
||||
$rss = fetch_feed("https://tboy.co/sportsnews/");
|
||||
if (!is_wp_error($rss)) { // Checks that the object is created correctly
|
||||
// Figure out how many total items there are, but limit it to 2.
|
||||
$maxitems = $rss->get_item_quantity(5);
|
||||
// Build an array of all the items, starting with element 0 (first element).
|
||||
$rss_items = $rss->get_items(0, $maxitems);
|
||||
}
|
||||
if (!empty($maxitems)) {
|
||||
?>
|
||||
<div class="rss-widget">
|
||||
<ul>
|
||||
<?php foreach ($rss_items as $item) { ?>
|
||||
<li><a class="rsswidget" href="<?php echo $item->get_permalink(); ?>" target="_blank"><?php echo $item->get_title(); ?></a> <span class="rss-date"><?php echo $item->get_date('j F Y'); ?></span></li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
Reference in New Issue
Block a user