widgets.php
51 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WP-Parsidate Admin Widget |
| 4 | * |
| 5 | * @author Parsa Kafi |
| 6 | * @package WP-Parsidate |
| 7 | * @subpackage Core/General |
| 8 | */ |
| 9 | |
| 10 | function wpp_add_dashboard_widgets() { |
| 11 | wp_add_dashboard_widget( |
| 12 | 'wpp_planet_widget', |
| 13 | __( 'WordPress Planet', 'wp-parsidate' ), |
| 14 | 'wpp_planet_widget_function' |
| 15 | ); |
| 16 | } |
| 17 | |
| 18 | function wpp_planet_widget_function() { |
| 19 | $rss = fetch_feed( 'http://wp-planet.ir/feed' ); |
| 20 | |
| 21 | $max_items = $rss_items = 0; |
| 22 | |
| 23 | if ( ! is_wp_error( $rss ) ) { |
| 24 | $max_items = $rss->get_item_quantity( 5 ); |
| 25 | $rss_items = $rss->get_items( 0, $max_items ); |
| 26 | } |
| 27 | ?> |
| 28 | <div class="rss-widget"> |
| 29 | <ul> |
| 30 | <?php if ( $max_items == 0 ) { |
| 31 | echo "<li>" . __( 'No items', 'wp-parsidate' ) . "</li>"; |
| 32 | } else { |
| 33 | $date_format = get_option( 'date_format' ); |
| 34 | foreach ( $rss_items as $item ) { |
| 35 | ?> |
| 36 | <li> |
| 37 | <a href="<?php echo esc_url( $item->get_permalink() ); ?>" target="_blank" |
| 38 | title="<?php echo esc_html( parsidate( "Y F d H:i:s", $item->get_date( "Y-m-d H:i:s" ) ) ); ?>"> |
| 39 | <?php echo esc_html( $item->get_title() ); ?> |
| 40 | </a> |
| 41 | <span class="rss-date"><?php echo esc_html( parsidate( $date_format, $item->get_date( "Y-m-d H:i:s" ) ) ); ?></span> |
| 42 | <div class="rssSummary"> |
| 43 | <?php //echo esc_url( $item->get_description() ); ?> |
| 44 | </div> |
| 45 | </li> |
| 46 | <?php } |
| 47 | } ?> |
| 48 | </ul> |
| 49 | </div> |
| 50 | <?php |
| 51 | } |