'widget_recent_posts_with_video', 'description' => esc_html__( 'Display most recent video posts.', 'passport' ) ); parent::__construct( 'passport_recent_posts_with_video_widget', esc_html__( 'Passport Recent Posts with Video', 'passport' ), $widget_ops ); $this->alt_option_name = 'widget_recent_posts_with_video'; add_action( 'wp_enqueue_scripts', array( $this, 'passport_widget_inline_style' ) ); } /** * Styling the widget */ public function passport_widget_inline_style() { $i = 0; $widget_options = get_option( $this->option_name ); $custom_widget_css = ''; if( is_array( $widget_options ) && count( $widget_options ) > 0 ) { foreach ( $widget_options as $key => $widget_option ) { $widget_title_bgcolor_option = isset( $widget_option['widget_title_bgcolor'] ) ? $widget_option['widget_title_bgcolor'] : ''; if ( isset( $widget_title_bgcolor_option ) ) { $custom_widget_css .= "#{$this->id_base}-{$key} .widget-title {"; $custom_widget_css .= ! empty( $widget_title_bgcolor_option ) ? 'background-color:'. $widget_title_bgcolor_option .';' :'background-color: #333333;'; $custom_widget_css .= "}"; $custom_widget_css .= "#{$this->id_base}-{$key} .widget-title span {"; $custom_widget_css .= 'color: #ffffff;'; $custom_widget_css .= "}"; } $i++; } } wp_add_inline_style( PASSPORT_THEME_SLUG . '-custom-style', $custom_widget_css ); } // Creating widget front-end // This is where the action happens public function widget( $args, $instance ) { $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; $number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : 5; $show_title = ! empty( $instance['show_title'] ) ? $instance['show_title'] : false; $show_video = ! empty( $instance['show_video'] ) ? $instance['show_video'] : false; $show_date = ! empty( $instance['show_date'] ) ? $instance['show_date'] : false; $show_excerpt = ! empty( $instance['show_excerpt'] ) ? $instance['show_excerpt'] : false; $widget_icon = ! empty( $instance['widget_icon'] ) ? $instance['widget_icon'] : ''; $widget_args = array( 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true, 'post__not_in' => array( get_the_ID() ), //Not include current post 'tax_query' => array( 'relation' => 'OR', array( 'taxonomy' => 'category', 'field' => 'slug', 'terms' => array( 'video' ), ), array( 'taxonomy' => 'post_format', 'field' => 'slug', 'terms' => array( 'post-format-video' ), ), ), ); $wp_query = new WP_Query( $widget_args ); ?> have_posts() ) : ?> '. $title .''; } ?>
id="get_field_id( 'show_title' ); ?>" name="get_field_name( 'show_title' ); ?>" />
id="get_field_id( 'show_video' ); ?>" name="get_field_name( 'show_video' ); ?>" />
id="get_field_id( 'show_date' ); ?>" name="get_field_name( 'show_date' ); ?>" />
id="get_field_id( 'show_excerpt' ); ?>" name="get_field_name( 'show_excerpt' ); ?>" />