'widget_recent_posts_with_thumbnails', 'description' => esc_html__( 'Display most recent posts with thumbnails.', 'passport' ) ); parent::__construct( 'passport_recent_posts_with_thumbnails_widget', esc_html__('Passport Recent Posts with Thumbnails', 'passport'), $widget_ops ); $this->alt_option_name = 'widget_recent_posts_with_thumbnails'; 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'] : ''; $content_column = get_theme_mod( 'section_1_settings' ); $number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : 5; $show_title = ! empty( $instance['show_title'] ) ? $instance['show_title'] : false; $show_image = ! empty( $instance['show_image'] ) ? $instance['show_image'] : false; $image_position = ! empty( $instance['image_position'] ) ? $instance['image_position'] : 'left' ; $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'] : ''; $post_type = array( 'post' ); $widget_args = array( 'post_type' => $post_type, '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 'meta_query' => array( array( 'key' => '_thumbnail_id', 'compare' => '!=', 'value' => '' ) ) ); $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_image' ); ?>" name="get_field_name( 'show_image' ); ?>" />
id="get_field_id( 'show_date' ); ?>" name="get_field_name( 'show_date' ); ?>" />
id="get_field_id( 'show_excerpt' ); ?>" name="get_field_name( 'show_excerpt' ); ?>" />