__( 'World cup 2018 News Widget', 'text_domain' ), ) // Args ); wp_enqueue_script('worldCupNewsJs',plugins_url('worldcup2018_script.js',__FILE__ ), array('jquery')); wp_localize_script( 'worldCupNewsJs', 'my_ajax_url', admin_url( 'admin-ajax.php' ) ); /* AJAX Callback */ add_action( 'wp_ajax_update_worldcup_news_ajax', array($this, 'update_worldcup_news_ajax')); add_action( 'wp_ajax_nopriv_update_worldcup_news_ajax',array($this,'update_worldcup_news_ajax')); }//end of function construct //function handle ajax request admin and non priv both public function update_worldcup_news_ajax(){ $this::widget_area_content(); wp_die(); } public function form( $instance ) { if ( isset( $instance[ 'title' ] ) ) { $title = $instance[ 'title' ]; } else { $title = __( 'World Cup 2018 News', 'text_domain' ); } ?>


Width: X  Height:

set_item_limit(1); $maxitems =0; // Checks that the object is created correctly if ( ! is_wp_error( $feed ) ){ // Figure out how many total items there are, but limit it to 5. $maxitems = $feed->get_item_quantity(); $feed->force_feed(true); $feed->enable_order_by_date(false); // Build an array of all the items, starting with element 0 (first element). $rss_items = $feed->get_items(); } if($maxitems != 0){ $i=1; echo ''; // Loop through each feed item and display each item as a hyperlink. foreach ( $rss_items as $item ){ if ($enclosure = $item->get_enclosure()) { if(!empty($item->get_content())){ echo '
'; echo '
'; echo '
'.$item->get_title().'
'; echo ''; echo '
'; echo '

'; echo ''; $i++; } else{ echo '
'; echo ''; echo '
'.$item->get_title().'
'; echo ''; echo '
'; echo '
'; } } // echo ''; //echo "
  • ".$item->get_content()."
  • "; } echo '
    '; echo '

    '.$feed->get_copyright().'

    '; echo ''; echo ''; echo ''; echo '
    '; }//end of if }//end of function /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget( $args, $instance ) { add_thickbox(); extract( $args ); $title = apply_filters( 'widget_title', $instance['title'] ); echo $before_widget; if ( ! empty( $title ) ) echo $before_title . $title . $after_title; extract( $args ); $title = apply_filters( 'widget_title', $instance['title'] ); if(!empty($instance['worldcup_news_widget_height'])){ $height = $instance['worldcup_news_widget_height']; } else{ $height = '500'; } if(!empty($instance['worldcup_news_widget_width'])){ $width = $instance['worldcup_news_widget_width']; } else{ $width = '300'; } //add filter set time for feed cache add_filter('wp_feed_cache_transient_lifetime', array($this, 'set_cache_time')); echo '
    ' ; // echo '
    '.str_replace('- News','',$feed->get_title()).'
    '; $this::widget_area_content(); echo '
    ';//end of feed content div } }//end of class /*function resgiter widget as plguin*/ function register_world_cup_2018_news(){ register_widget( "world_cup_2018_news" ); } add_action( 'widgets_init', 'register_world_cup_2018_news' );