'widget_featured_posts_by_category clearfix', 'description' => esc_html__( 'Display featured posts by specific category', 'passport' ) ); parent::__construct( 'passport_featured_posts_by_category_widget', esc_html__( 'Passport Featured Posts by Category', 'passport' ), $widget_ops ); $this->alt_option_name = 'widget_featured_posts_by_category'; 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 ) { global $passport_number; $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; $category_name = ! empty( $instance['category_name'] ) ? $instance['category_name'] : 'uncategories'; $image_position = ! empty( $instance['image_position'] ) ? $instance['image_position'] : 'left' ; $exclude = ! empty( $instance['exclude'] ) ? $instance['exclude'] : ''; $excludeArry = explode( ',', $exclude ); $orderby = ! empty( $instance['orderby'] ) ? $instance['orderby'] : 'date'; $order = ! empty( $instance['order'] ) ? $instance['order'] : 'desc'; $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( 'post_type' => 'post', 'category_name' => $category_name, 'posts_per_page' => $passport_number, 'order' => $order, 'orderby' => $orderby, 'post__not_in' => $excludeArry ); $wp_query = new WP_Query( $widget_args ); ?> '. $title .''; } ?>
'', 'category_name' => 'uncategories', 'image_position' => 'left', 'orderby' => 'date', 'order' => 'desc', 'exclude' => '', 'widget_icon' => '', 'widget_title_bgcolor' => '#333333' ) ); $title = $instance['title']; $category_name = $instance['category_name']; $image_position = $instance['image_position']; $orderby = $instance['orderby']; $order = $instance['order']; $exclude = $instance['exclude']; $widget_icon = $instance['widget_icon']; $widget_title_bgcolor = $instance['widget_title_bgcolor']; // Widget admin form ?>