'widget_most_popular_posts', 'description' => esc_html__( 'Most popular posts', 'passport' ) ); parent::__construct( 'passport_most_popular_posts_widget', esc_html__( 'Passport Most Popular Posts', 'passport' ), $widget_ops ); $this->alt_option_name = 'widget_most_popular_posts'; 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 public function widget( $args, $instance ) { global $post; $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); $number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : 5; $widget_icon = ! empty( $instance['widget_icon'] ) ? $instance['widget_icon'] : ''; $frontpage_id = get_option( 'page_on_front' ); $attachment_id = get_post_thumbnail_id( $frontpage_id ); $widget_args = array( 'meta_key' => '_post_like_count', 'orderby' => 'meta_value_num', 'order' => 'DESC', 'posts_per_page' => $number, 'ignore_sticky_posts' => TRUE, ); $wp_query = new WP_Query( $widget_args ); echo $args['before_widget']; if ( ! empty( $title ) ) { echo '