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-logos.php |
<?php // MeanThemes Homepage Widget for Logos. /* * * This widget uses the Custom post type for meanthemes_logos (via the MeanThemes tools plugin) * */ // Register widget add_action('widgets_init', 'meanthemes_home_logos_widget'); function meanthemes_home_logos_widget() { register_widget( 'meanthemes_home_logos' ); } // Setup widget class class meanthemes_home_logos extends WP_Widget { function __construct() { $widget_name = __( 'MT Homepage: Logos' , 'meanthemes' ); $widget_classname = "meanthemes_home_logos"; $widget_description = __('This widget includes the logos you have set up via the "Logos" 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_logos-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 = 8; } else { $posts_per_page = $post_amount; } if ( isset( $instance[ 'link_new' ] ) ) { $link_new = $instance[ 'link_new' ]; } else { $link_new = ""; } if ( $link_new === "" ) { $link_new = ''; } else { $link_new = $link_new; } if ( isset( $instance[ 'auto_rotate' ] ) ) { $auto_rotate = $instance[ 'auto_rotate' ]; } else { $auto_rotate = ""; } if ( $auto_rotate === "" ) { $auto_rotate = 'true'; } else { $auto_rotate = $auto_rotate; } if ( isset( $instance[ 'slideshow_speed' ] ) ) { $slideshow_speed = $instance[ 'slideshow_speed' ]; } else { $slideshow_speed = ""; } if ( $slideshow_speed === "" ) { $slideshow_speed = '7000'; } else { $slideshow_speed = $slideshow_speed; } 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-logos" id="<?php echo esc_attr( $this->id ); ?>"> <?php // Get All Logo Posts wp_reset_postdata(); $main_query = new WP_Query( array ( 'post_type' => 'logo', 'posts_per_page' => $posts_per_page ) ); if ( $main_query->have_posts() ) { ?> <?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 } ?> </div> <?php } ?> <div class="loop logo-loop"> <div class="logo-carousel"> <div class="owl-carousel"> <?php } while ( $main_query->have_posts() ) : $main_query->the_post(); global $post; ?> <?php // Get custom meta $prefix = "_logo_"; $link = get_post_meta($post->ID, $prefix . 'link', true); ?> <div <?php post_class( 'logo-item' ); ?> id="post-<?php the_ID(); ?>"> <div class="logo-table"> <div class="logo-table-cell"> <?php // If we have a featured image, show it if ( has_post_thumbnail() ) { ?> <?php if ( $link ) { ?><a href="<?php echo esc_url( $link ); ?>" title="<?php esc_html( the_title() ); ?>"<?php if ( $link_new === '1' ) { echo ' target="_blank"'; } ?>><?php } ?> <?php the_post_thumbnail( 'logo' ); ?> <?php if ( $link ) { ?></a><?php } ?> <?php } ?> </div> </div> </div> <?php endwhile; if ( $main_query->have_posts() ) { ?> </div> </div> <?php if ( $button_text && $button_url ) { ?> <div class="widget-buttons"> <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> </div> <?php } ?> </div> <?php } ?> </section> <script> jQuery(document).ready(function() { "use strict"; var owl = jQuery(".home-widget#<?php echo esc_attr( $this->id ); ?> .owl-carousel"); owl.owlCarousel({ pagination: false, navigation: true, navigationText: ['<i class="fa fa-chevron-left"></i>','<i class="fa fa-chevron-right"></i>'], <?php if ( $auto_rotate === "true" ) { ?> autoPlay: <?php echo esc_js( $slideshow_speed ); ?>, <?php } ?> items : 5, //10 items above 1000px browser width itemsDesktop : [1200,4], //4 items between 1800px and 901px itemsDesktopSmall : [900,3], // betweem 900px and 601px itemsTablet: [600,2], //2 items between 600 and 0 itemsMobile : [540,1], // itemsMobile disabled - inherit from itemsTablet option }); }); </script> <?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['link_new'] = esc_attr( $new_instance['link_new'] ); $instance['auto_rotate'] = esc_attr( $new_instance['auto_rotate'] ); $instance['slideshow_speed'] = esc_attr( $new_instance['slideshow_speed'] ); $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" => "", "link_new" => "", "auto_rotate" => "", "slideshow_speed" => "", "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_url( $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('link_new') ); ?>"><?php _e( 'Make logo links open in new tab/window' , 'meanthemes' ); ?></label><br /> <select name="<?php echo esc_attr( $this->get_field_name('link_new') ); ?>" id="<?php echo esc_attr( $this->get_field_id('link_new') ); ?>"> <option value="0" <?php if ( $instance['link_new'] !== '1' ) { ?>selected<?php } ?>>No</option> <option value="1" <?php if ( $instance['link_new'] !== '0' ) { ?>selected<?php } ?>>Yes</option> </select> </p> <p> <label for="<?php echo esc_attr( $this->get_field_id('auto_rotate') ); ?>"><?php _e( 'Auto rotate:' , 'meanthemes' ); ?></label><br /> <select name="<?php echo esc_attr( $this->get_field_name('auto_rotate') ); ?>" id="<?php echo esc_attr( $this->get_field_id('auto_rotate') ); ?>"> <option value="false" <?php if ( $instance['auto_rotate'] !== 'true' ) { ?>selected<?php } ?>>No</option> <option value="true" <?php if ( $instance['auto_rotate'] !== 'false' ) { ?>selected<?php } ?>>Yes</option> </select> </p> <p> <label for="<?php echo esc_attr( $this->get_field_id('slideshow_speed') ); ?>"><?php _e( 'Carousel Speed:' , 'meanthemes' ); ?></label><br /> <select name="<?php echo esc_attr( $this->get_field_name('slideshow_speed') ); ?>" id="<?php echo esc_attr( $this->get_field_id('slideshow_speed') ); ?>"> <option value="7000" <?php if ( $instance['slideshow_speed'] === '7000' ) { ?>selected<?php } ?>>7 seconds</option> <option value="1000" <?php if ( $instance['slideshow_speed'] === '1000' ) { ?>selected<?php } ?>>1 second</option> <option value="2000" <?php if ( $instance['slideshow_speed'] === '2000' ) { ?>selected<?php } ?>>2 seconds</option> <option value="3000" <?php if ( $instance['slideshow_speed'] === '3000' ) { ?>selected<?php } ?>>3 seconds</option> <option value="4000" <?php if ( $instance['slideshow_speed'] === '4000' ) { ?>selected<?php } ?>>4 seconds</option> <option value="5000" <?php if ( $instance['slideshow_speed'] === '5000' ) { ?>selected<?php } ?>>5 seconds</option> <option value="6000" <?php if ( $instance['slideshow_speed'] === '6000' ) { ?>selected<?php } ?>>6 seconds</option> <option value="7000" <?php if ( $instance['slideshow_speed'] === '7000' ) { ?>selected<?php } ?>>7 seconds</option> <option value="8000" <?php if ( $instance['slideshow_speed'] === '8000' ) { ?>selected<?php } ?>>8 seconds</option> <option value="9000" <?php if ( $instance['slideshow_speed'] === '9000' ) { ?>selected<?php } ?>>9 seconds</option> <option value="10000" <?php if ( $instance['slideshow_speed'] === '10000' ) { ?>selected<?php } ?>>10 seconds</option> <option value="11000" <?php if ( $instance['slideshow_speed'] === '11000' ) { ?>selected<?php } ?>>11 seconds</option> <option value="12000" <?php if ( $instance['slideshow_speed'] === '12000' ) { ?>selected<?php } ?>>12 seconds</option> <option value="13000" <?php if ( $instance['slideshow_speed'] === '13000' ) { ?>selected<?php } ?>>13 seconds</option> <option value="14000" <?php if ( $instance['slideshow_speed'] === '14000' ) { ?>selected<?php } ?>>14 seconds</option> <option value="15000" <?php if ( $instance['slideshow_speed'] === '15000' ) { ?>selected<?php } ?>>15 seconds</option> </select> </p> <p> <label for="<?php echo esc_attr( $this->get_field_id('post_amount') ); ?>"><?php _e( 'Show this number of logos:' , '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 '8'; } 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 } } ?>