Current Path : /var/test/www/ya/wp-content/themes/youthy/framework/widgets/ |
Current File : /var/test/www/ya/wp-content/themes/youthy/framework/widgets/widget-services.php |
<?php // MeanThemes Homepage Widget for Services. /* * * This widget uses the Custom post type for meanthemes_services (via the MeanThemes tools plugin) * */ // Register widget add_action('widgets_init', 'meanthemes_home_services_widget'); function meanthemes_home_services_widget() { register_widget( 'meanthemes_home_services' ); } // Setup widget class class meanthemes_home_services extends WP_Widget { function __construct() { $widget_name = __( 'MT Homepage: Services' , 'meanthemes' ); $widget_classname = "meanthemes_home_services"; $widget_description = __('This widget includes the services you have set up via the "Services" Custom Post Type, with a few extra options.', 'meanthemes'); // Set widget classname and description from above $widget_ops = array( 'classname' => $widget_classname, 'description' => $widget_description, ); parent::__construct('meanthemes_home_services-widget', $widget_name, $widget_ops); } // Setup widget output function widget($args, $instance) { extract($args); // Variables from the widget settings. if ( isset( $instance[ 'title' ] ) ) { $title = $instance[ 'title' ]; } else { $title = ""; } if ( isset( $instance[ 'description' ] ) ) { $description = $instance[ 'description' ]; } else { $description = ""; } if ( isset( $instance[ 'button_text' ] ) ) { $button_text = $instance[ 'button_text' ]; } else { $button_text = ""; } if ( isset( $instance[ 'button_url' ] ) ) { $button_url = $instance[ 'button_url' ]; } else { $button_url = ""; } if ( isset( $instance[ 'button_color' ] ) ) { $button_color = $instance[ 'button_color' ]; } else { $button_color = ""; } if ( isset( $instance[ 'post_amount' ] ) ) { $post_amount = $instance[ 'post_amount' ]; } else { $post_amount = ""; } if ( $post_amount === "" ) { $posts_per_page = 6; } else { $posts_per_page = $post_amount; } if ( isset( $instance[ 'bg_color' ] ) ) { $bg_color = $instance[ 'bg_color' ]; } else { $bg_color = ""; } if ( isset( $instance[ 'text_color' ] ) ) { $text_color = $instance[ 'text_color' ]; } else { $text_color = ""; } if ( $button_color || $bg_color || $text_color ) { ?> <style type="text/css"> <?php if ( $button_color ) { ?> .home-widget#<?php echo esc_attr( $this->id ); ?> .btn.info-btn, .home-widget#<?php echo esc_attr( $this->id ); ?> .btn.info-btn:hover { background-color: <?php echo esc_html( $button_color ); ?> !important; } <?php } ?> <?php if ( $bg_color ) { ?> .home-widget#<?php echo esc_attr( $this->id ); ?> { background-color: <?php echo esc_html( $bg_color ); ?> !important; } <?php } ?> <?php if ( $text_color ) { ?> .home-widget#<?php echo esc_attr( $this->id ); ?> .widget-info { color: <?php echo esc_html( $text_color ); ?> !important; } <?php } ?> </style> <?php } // Widget HTML output ?> <section class="home-widget widget-services" id="<?php echo esc_attr( $this->id ); ?>"> <?php // Get All Service Posts wp_reset_postdata(); $main_query = new WP_Query( array ( 'post_type' => 'service', 'posts_per_page' => $posts_per_page ) ); if ( $main_query->have_posts() ) { ?> <div class="service-loop"> <?php } while ( $main_query->have_posts() ) : $main_query->the_post(); get_template_part('service/item'); endwhile; if ( $main_query->have_posts() ) { ?> </div> <?php } ?> <?php if ( $title || $description ) { ?> <div class="widget-info"> <?php if ( $title ) { ?> <h2><?php echo esc_html( $title ); ?></h2> <?php } ?> <?php if ( $description ) { ?> <div class="widget-description"> <?php echo balanceTags( apply_filters( 'the_content', $description ) ); ?> </div> <?php if ( $button_text && $button_url ) { ?> <a class="btn info-btn" href="<?php echo esc_url( $button_url ); ?>" title="<?php echo esc_html( $button_text ); ?>"><?php echo esc_html( $button_text ); ?> <i class="fa fa-arrow-right"></i></a> <?php } ?> <?php } ?> </div> <?php } ?> </section> <?php } // Variables for updating widget, these should match above but use santization methods function update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = esc_html( $new_instance['title'] ); $instance['description'] = esc_attr( $new_instance['description'] ); $instance['button_text'] = esc_html( $new_instance['button_text'] ); $instance['button_url'] = esc_url( $new_instance['button_url'] ); $instance['button_color'] = esc_html( $new_instance['button_color'] ); $instance['post_amount'] = esc_attr( $new_instance['post_amount'] ); $instance['bg_color'] = esc_html( $new_instance['bg_color'] ); $instance['text_color'] = esc_html( $new_instance['text_color'] ); return $instance; } // Setup widget form that appears in Appearance > Widgets function form($instance) { // Again set the variables... again! $defaults = array( "title" => "", "description" => "", "button_text" => "", "button_url" => "", "button_color" => "", "post_amount" => "", "bg_color" => "", "text_color" => "" ); $instance = wp_parse_args( (array) $instance, $defaults ); ?> <p> <label for="<?php echo esc_attr( $this->get_field_id('title') ); ?>"><?php _e( 'Title:' , 'meanthemes' ); ?></label><br /> <input type="text" name="<?php echo esc_attr( $this->get_field_name('title') ); ?>" id="<?php echo esc_attr( $this->get_field_id('title') ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat" /> </p> <p> <label for="<?php echo esc_attr( $this->get_field_id('description') ); ?>"><?php _e( 'Short description:' , 'meanthemes' ); ?></label><br /> <textarea name="<?php echo esc_attr( $this->get_field_name('description') ); ?>" rows="6" style="width: 100%;" id="<?php echo esc_attr( $this->get_field_id('description') ); ?>"><?php echo balanceTags( $instance['description'] ); ?></textarea> </p> <p> <label for="<?php echo esc_attr( $this->get_field_id('button_text') ); ?>"><?php _e( 'Button Text:' , 'meanthemes' ); ?></label><br /> <input type="text" name="<?php echo esc_attr( $this->get_field_name('button_text') ); ?>" id="<?php echo esc_attr( $this->get_field_id('button_text') ); ?>" value="<?php echo esc_attr( $instance['button_text'] ); ?>" class="widefat" /> </p> <p> <label for="<?php echo esc_attr( $this->get_field_id('button_url') ); ?>"><?php _e( 'Button URL:' , 'meanthemes' ); ?></label><br /> <input type="text" name="<?php echo esc_attr( $this->get_field_name('button_url') ); ?>" id="<?php echo esc_attr( $this->get_field_id('button_url') ); ?>" value="<?php echo esc_attr( $instance['button_url'] ); ?>" class="widefat" /> </p> <p> <label for="<?php echo esc_attr( $this->get_field_id('button_color') ); ?>"><?php _e( 'Button Color:' , 'meanthemes' ); ?></label><br /> <input type="text" name="<?php echo esc_attr( $this->get_field_name('button_color') ); ?>" id="<?php echo esc_attr( $this->get_field_id('button_color') ); ?>" value="<?php echo esc_attr( $instance['button_color'] ); ?>" class="widefat color-field" /> </p> <p> <label for="<?php echo esc_attr( $this->get_field_id('post_amount') ); ?>"><?php _e( 'Show this number of posts:' , 'meanthemes' ); ?></label><br /> <input type="number" name="<?php echo esc_attr( $this->get_field_name('post_amount') ); ?>" id="<?php echo esc_attr( $this->get_field_id('post_amount') ); ?>" value="<?php if ( $instance['post_amount'] === '' ) { echo '6'; } else { echo esc_attr( $instance['post_amount'] ); } ?>" class="widefat" /> </p> <p> <label for="<?php echo esc_attr( $this->get_field_id('bg_color') ); ?>"><?php _e( 'Background Color:' , 'meanthemes' ); ?></label><br /> <input type="text" name="<?php echo esc_attr( $this->get_field_name('bg_color') ); ?>" id="<?php echo esc_attr( $this->get_field_id('bg_color') ); ?>" value="<?php echo esc_attr( $instance['bg_color'] ); ?>" class="widefat color-field" /> </p> <p> <label for="<?php echo esc_attr( $this->get_field_id('text_color') ); ?>"><?php _e( 'Text Color:' , 'meanthemes' ); ?></label><br /> <input type="text" name="<?php echo esc_attr( $this->get_field_name('text_color') ); ?>" id="<?php echo esc_attr( $this->get_field_id('text_color') ); ?>" value="<?php echo esc_attr( $instance['text_color'] ); ?>" class="widefat color-field" /> </p> <?php } } ?>