'widget_accordion clearfix', 'description' => esc_html__( 'Use Bootstrap Accordion', 'passport' ) ); parent::__construct( 'passport_accordion_widget', esc_html__( 'Passport Accordion', 'passport' ), $widget_ops ); $this->alt_option_name = 'widget_accordion'; 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} .panel-heading {"; $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} .panel-title > a {"; $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 $post; $category_name = ! empty( $instance['category_name'] ) ? $instance['category_name'] : 'uncategories'; $number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : 5; $exclude = ! empty( $instance['exclude'] ) ? $instance['exclude'] : ''; $excludeArry = explode( ',', $exclude ); $orderby = ! empty( $instance['orderby'] ) ? $instance['orderby'] : 'date'; $order = ! empty( $instance['order'] ) ? $instance['order'] : 'desc'; $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' => $number, 'order' => $order, 'orderby' => $orderby, 'post__not_in' => $excludeArry ); $wp_query = new WP_Query( $widget_args ); ?>
have_posts() ) : ?> have_posts() ) : $wp_query->the_post(); $archive_year = get_the_time( 'Y' ); $archive_month = get_the_time( 'm' ); $archive_day = get_the_time( 'd' ); ?>
'uncategories', 'number' => '5', 'orderby' => 'date', 'order' => 'desc', 'exclude' => '', 'widget_title_bgcolor' => '#333333' ) ); $category_name = $instance['category_name']; $number = $instance['number']; $orderby = $instance['orderby']; $order = $instance['order']; $exclude = $instance['exclude']; $widget_title_bgcolor = $instance['widget_title_bgcolor']; // Widget admin form ?>




slug . ''; } $orderbyArry = array( 'none', 'date', 'author', 'title', 'name', 'parent', 'type', 'modified', 'rand' ); $orderArry = array( ' desc' , 'asc' ); //Update new instances if ( in_array( $new_instance['category_name'], $catsArray ) ) { $instance['category_name'] = $new_instance['category_name']; } else { $instance['category_name'] = 'uncategories'; } $instance['number'] = (int) $new_instance['number']; if ( in_array( $new_instance['orderby'], $orderbyArry ) ) { $instance['orderby'] = $new_instance['orderby']; } else { $instance['orderby'] = 'date'; } if ( in_array( $new_instance['order'], $orderArry ) ) { $instance['order'] = $new_instance['order']; } else { $instance['order'] = 'desc'; } $instance['exclude'] = wp_filter_nohtml_kses( $new_instance['exclude'] ); $instance['widget_title_bgcolor'] = wp_filter_nohtml_kses( $new_instance['widget_title_bgcolor'] ); return $instance; } } // Class widget ends here // Register and load the widget function passport_accordion_load_widget() { register_widget( 'Passport_Accordion_Widget' ); } add_action( 'widgets_init', 'passport_accordion_load_widget' );