Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Bottom_Widget extends WP_Widget {
- function __construct() {
- parent::__construct(
- // Выбираем ID для своего виджета
- 'bottom_top',
- // Название виджета, показано в консоли
- __('Bottom Widget', 'bottom_widget_domain'),
- // Описание виджета
- array( 'description' => __( 'Latest Project SLIDER', 'bottom_widget_domain' ), )
- );
- }
- // Обновление виджета
- public function update( $new_instance, $old_instance ) {
- $instance = array();
- $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
- $instance['show_logo'] = !empty($new_instance['show_logo']) ? 1 : 0;
- $instance['soc_ico'] = !empty($new_instance['soc_ico']) ? 1 : 0;
- $instance['show_search'] = !empty($new_instance['show_search']) ? 1 : 0;
- $instance['twitter_url'] = ( ! empty( $new_instance['twitter_url'] ) ) ? strip_tags( $new_instance['twitter_url'] ) : '';
- $instance['facebook_url'] = ( ! empty( $new_instance['facebook_url'] ) ) ? strip_tags( $new_instance['facebook_url'] ) : '';
- $instance['rss_url'] = ( ! empty( $new_instance['rss_url'] ) ) ? strip_tags( $new_instance['rss_url'] ) : '';
- $instance['linked_url'] = ( ! empty( $new_instance['linked_url'] ) ) ? strip_tags( $new_instance['linked_url'] ) : '';
- $instance['skype_url'] = ( ! empty( $new_instance['skype_url'] ) ) ? strip_tags( $new_instance['skype_url'] ) : '';
- return $instance;
- }
- // Создаем код для виджета -
- // сначала небольшая идентификация
- public function widget( $args, $instance ) {
- $title = apply_filters( 'widget_title', $instance['title'] );
- $show_logo = isset( $instance['show_logo'] ) ? (bool) $instance['show_logo'] : true;
- $soc_ico = isset( $instance['soc_ico'] ) ? (bool) $instance['soc_ico'] : true;
- $show_search = isset( $instance['show_search'] ) ? (bool) $instance['show_search'] : true;
- $twitter_url = $instance['twitter_url'];
- $facebook_url = $instance['facebook_url'];
- $rss_url = $instance['rss_url'];
- $linked_url = $instance['linked_url'];
- $skype_url = $instance['skype_url'];
- // до и после идентификации переменных темой
- echo $args['before_widget'];
- if ( ! empty( $title ) )
- echo $args['before_title'] . $title . $args['after_title'];
- if($show_logo == true) {
- echo '<div class="logo_sidebar">
- <a href="http://vlad.net/"><img src="http://vlad.net/wp-content/themes/buildhome/img/logo-bottom.png" alt="logo"></a>
- </div>';
- }
- if($soc_ico == true) {
- echo '<div class="soc_ico_sidebar">
- <ul>';
- if($facebook_url != '') {
- echo '<li><a href="'.$facebook_url.'"><span class="icon icon-facebook"></span></a></li>';
- }
- if($twitter_url != '') {
- echo '<li><a href="'.$twitter_url.'"><span class="icon icon-twitter"></span></a></li>';
- }
- if($rss_url != '') {
- echo '<li><a href="'.$rss_url.'"><span class="icon icon-rss"></span></a></li>';
- }
- if($linked_url != '') {
- echo '<li><a href="'.$linked_url.'"><span class="icon icon-linked"></span></a></li>';
- }
- if($skype_url != '') {
- echo '<li><a href="'.$skype_url.'"><span class="icon icon-skype"></span></a></li>';
- }
- echo '</ul>
- </div>';
- }
- if($show_search == true) {
- echo '<div class="search_bottom">
- <input type="text" placeholder="Search...">
- <button></button>
- </div>';
- }
- echo $args['after_widget'];
- }
- public function form( $instance ) {
- $defaults = array( 'title' => __('', 'example'));
- $instance = wp_parse_args( (array) $instance, $defaults );
- $show_logo = isset( $instance['show_logo'] ) ? (bool) $instance['show_logo'] : true;
- $soc_ico = isset( $instance['soc_ico'] ) ? (bool) $instance['soc_ico'] : true;
- $show_search = isset( $instance['show_search'] ) ? (bool) $instance['show_search'] : true;
- if ( isset( $instance[ 'twitter_url' ] ) ) {
- $twitter_url = $instance[ 'twitter_url' ];
- }else {
- $twitter_url = __( '', 'bottom_widget_domain' );
- }
- if ( isset( $instance[ 'facebook_url' ] ) ) {
- $facebook_url = $instance[ 'facebook_url' ];
- }else {
- $facebook_url = __( '', 'bottom_widget_domain' );
- }
- if ( isset( $instance[ 'rss_url' ] ) ) {
- $rss_url = $instance[ 'rss_url' ];
- }else {
- $rss_url = __( '', 'bottom_widget_domain' );
- }
- if ( isset( $instance[ 'linked_url' ] ) ) {
- $linked_url = $instance[ 'linked_url' ];
- }else {
- $linked_url = __( '', 'bottom_widget_domain' );
- }
- if ( isset( $instance[ 'skype_url' ] ) ) {
- $skype_url = $instance[ 'skype_url' ];
- }else {
- $skype_url = __( '', 'bottom_widget_domain' );
- }
- ?>
- <p>
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_logo'); ?>" name="<?php echo $this->get_field_name('show_logo'); ?>"<?php checked( $show_logo ); ?> />
- <label for="<?php echo $this->get_field_id('show_logo'); ?>"><?php _e( 'Display logo block?' ); ?></label></p>
- </p>
- <p>
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('soc_ico'); ?>" name="<?php echo $this->get_field_name('soc_ico'); ?>"<?php checked( $soc_ico ); ?> />
- <label for="<?php echo $this->get_field_id('soc_ico'); ?>"><?php _e( 'Display socials block?' ); ?></label></p>
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'facebook_url' ); ?>">Facebook Url</label>
- <input class="widefat" id="<?php echo $this->get_field_id( 'facebook_url' ); ?>"name="<?php echo $this->get_field_name( 'facebook_url' ); ?>" type="text" value="<?php echo esc_attr( $facebook_url ); ?>" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'twitter_url' ); ?>">Twitter Url</label>
- <input class="widefat" id="<?php echo $this->get_field_id( 'twitter_url' ); ?>"name="<?php echo $this->get_field_name( 'twitter_url' ); ?>" type="text" value="<?php echo esc_attr( $twitter_url ); ?>" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'rss_url' ); ?>">RSS Url</label>
- <input class="widefat" id="<?php echo $this->get_field_id( 'rss_url' ); ?>"name="<?php echo $this->get_field_name( 'rss_url' ); ?>" type="text" value="<?php echo esc_attr( $rss_url ); ?>" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'linked_url' ); ?>">Linked Url</label>
- <input class="widefat" id="<?php echo $this->get_field_id( 'linked_url' ); ?>"name="<?php echo $this->get_field_name( 'linked_url' ); ?>" type="text" value="<?php echo esc_attr( $linked_url ); ?>" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'skype_url' ); ?>">Skype Url</label>
- <input class="widefat" id="<?php echo $this->get_field_id( 'skype_url' ); ?>"name="<?php echo $this->get_field_name( 'skype_url' ); ?>" type="text" value="<?php echo esc_attr( $skype_url ); ?>" />
- </p>
- <p>
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_search'); ?>" name="<?php echo $this->get_field_name('show_search'); ?>"<?php checked( $show_search ); ?> />
- <label for="<?php echo $this->get_field_id('show_search'); ?>"><?php _e( 'Display search block?' ); ?></label></p>
- </p>
- <?php
- }
- }
- function bottom_widget() {
- register_widget( 'Bottom_Widget' );
- }
- add_action( 'widgets_init', 'bottom_widget' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement