'widget_parallax clearfix', 'description' => esc_html__( 'Parallax', 'passport' ) ); parent::__construct( 'passport_parallax_widget', esc_html__( 'Passport Parallax', 'passport' ), $widget_ops ); $this->alt_option_name = 'widget_parallax'; 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_id = isset( $widget_option['id'] ) ? $widget_option['id'] : ''; $widget_bg_attachment = isset( $widget_option['bg_attachment'] ) ? $widget_option['bg_attachment'] : ''; $widget_bg_height = isset( $widget_option['bg_height'] ) ? $widget_option['bg_height'] : ''; $widget_horizontal_position = isset( $widget_option['horizontal_position'] ) ? $widget_option['horizontal_position'] : ''; $widget_vertical_position = isset( $widget_option['vertical_position'] ) ? $widget_option['vertical_position'] : ''; $widget_title_color = isset( $widget_option['title_color'] ) ? $widget_option['title_color'] : ''; $widget_excerpt_color = isset( $widget_option['excerpt_color'] ) ? $widget_option['excerpt_color'] : ''; $widget_button_font_color = isset( $widget_option['button_font_color'] ) ? $widget_option['button_font_color'] : ''; $widget_button_border_color = isset( $widget_option['button_bg_color'] ) ? $widget_option['button_bg_color'] : ''; $widget_button_bg_color = isset( $widget_option['button_bg_color'] ) ? $widget_option['button_bg_color'] : ''; $thumb_id = get_post_thumbnail_id( $widget_id ); $thumb_url_array = wp_get_attachment_image_src( $thumb_id, 'full', true ); $thumb_url = $thumb_url_array[0]; if ( isset( $thumb_url ) || isset( $widget_bg_attachment ) || isset( $widget_bg_height ) || isset( $widget_horizontal_position ) || isset( $widget_vertical_position ) || isset( $widget_title_color ) || isset( $widget_excerpt_color ) || isset( $widget_button_font_color ) || isset( $widget_button_bg_color ) || isset( $widget_button_border_color ) ) { $custom_widget_css .= "#{$this->id_base}-{$key} .parallax {"; $custom_widget_css .= ! empty( $thumb_url ) ? 'background-image:url( '. $thumb_url .' );' : ''; $custom_widget_css .= 'background-position: 50% 0px;'; $custom_widget_css .= 'background-size: cover;'; $custom_widget_css .= ! empty( $widget_bg_attachment ) ? 'background-attachment: '. $widget_bg_attachment .';' : 'background-attachment: scroll;'; $custom_widget_css .= ! empty( $widget_bg_height ) ? 'height:'. $widget_bg_height .'px;' : 'height: 750px;'; $custom_widget_css .= "}"; $custom_widget_css .= "#{$this->id_base}-{$key} .parallax-wrapper {"; $custom_widget_css .= ! empty( $widget_bg_height ) ? 'min-height: '. $widget_bg_height .'px;' : 'min-height: 750px;'; $custom_widget_css .= "}"; $custom_widget_css .= "#{$this->id_base}-{$key} .parallax-headline {"; $custom_widget_css .= ! empty( $widget_horizontal_position ) ? 'text-align: '. $widget_horizontal_position .';' : 'text-align: center;'; $custom_widget_css .= ! empty( $widget_vertical_position ) ? 'vertical-align: '. $widget_vertical_position .';' : 'vertical-align: middle;'; $custom_widget_css .= "}"; $custom_widget_css .= "#{$this->id_base}-{$key} .parallax-title {"; $custom_widget_css .= ! empty( $widget_title_color ) ? 'color: '. $widget_title_color .';' : 'color: #ffffff;'; $custom_widget_css .= "}"; $custom_widget_css .= "#{$this->id_base}-{$key} .parallax-caption {"; $custom_widget_css .= ! empty( $widget_excerpt_color ) ? 'color: '. $widget_excerpt_color .';' : 'color: #A99D75;'; $custom_widget_css .= "}"; $custom_widget_css .= "#{$this->id_base}-{$key} .parallax-button {"; $custom_widget_css .= ! empty( $widget_button_font_color ) ? 'color: '. $widget_button_font_color .';' : 'color: #ffffff;'; $custom_widget_css .= ! empty( $widget_button_border_color ) ? 'border-color: '. $widget_button_border_color .';' : 'border-color: #ffffff;'; $custom_widget_css .= ! empty( $widget_button_bg_color ) ? 'background-color: '. $widget_button_bg_color .';' : 'background-color: transparent;'; $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 ) { $id = ! empty( $instance['id'] ) ? absint( $instance['id'] ) : ''; $button_text = ! empty( $instance['button_text']) ? $instance['button_text'] : ''; $img_post = get_post( $id ); $show_title = get_the_title( $id ); $show_excerpt = ! empty( $img_post ) ? $img_post->post_excerpt : ''; $widget_args = array( 'p' => $id, 'post_type' => 'post' ); $wp_query = new WP_Query( $widget_args ); if ( $wp_query->have_posts() ) : ?>

'', 'bg_attachment' => 'scroll', 'bg_height' => '', 'horizontal_position' => 'center', 'vertical_position' => 'middle', 'button_text' => '', 'title_color' => '#ffffff', 'excerpt_color' => '#A99D75', 'button_font_color' => '#ffffff', 'button_bg_color' => '#034f84' ) ); $id = $instance['id']; $bg_attachment = $instance['bg_attachment']; $bg_height = $instance['bg_height']; $horizontal_position= $instance['horizontal_position']; $vertical_position = $instance['vertical_position']; $button_text = $instance['button_text']; $title_color = $instance['title_color']; $excerpt_color = $instance['excerpt_color']; $button_font_color = $instance['button_font_color']; $button_bg_color = $instance['button_bg_color']; // Widget admin form ?>