add_control( 'section_blog_posts', [ 'label' => __( 'Blog Posts', 'astore-companion' ), 'type' => Controls_Manager::SECTION, ] ); $this->add_control( 'posts_per_page', [ 'label' => __( 'Number of Posts', 'astore-companion' ), 'type' => Controls_Manager::SELECT, 'default' => 6, 'section' => 'section_blog_posts', 'options' => [ 2 => __( '2', 'astore-companion' ), 3 => __( '3', 'astore-companion' ), 4 => __( '4', 'astore-companion' ), 5 => __( '5', 'astore-companion' ), 6 => __( '6', 'astore-companion' ), 7 => __( '7', 'astore-companion' ), 8 => __( '8', 'astore-companion' ), 9 => __( '9', 'astore-companion' ), 10 => __( '10', 'astore-companion' ), 11 => __( '11', 'astore-companion' ), 12 => __( '12', 'astore-companion' ), ] ] ); $this->add_control( 'columns', [ 'label' => __( 'Columns', 'astore-companion' ), 'type' => Controls_Manager::SELECT, 'default' => 3, 'section' => 'section_blog_posts', 'options' => [ 2 => __( '2', 'astore-companion' ), 3 => __( '3', 'astore-companion' ), 4 => __( '4', 'astore-companion' ), ] ] ); } protected function render( $instance = [] ) { // get our input from the widget settings. $settings = $this->get_settings(); $post_count = ! empty( $settings['posts_per_page'] ) ? (int)$settings['posts_per_page'] : 6; $columns = ! empty( $settings['columns'] ) ? $settings['columns'] : '3'; $class_column = 'col-md-4'; switch( $columns ){ case "1": $class_column = 'col-md-12'; break; case "2": $class_column = 'col-md-6'; break; case "3": $class_column = 'col-md-4'; break; case "4": $class_column = 'col-md-3'; break; } if( !is_numeric($columns) || $columns<=0 ) $columns = 3; ?>
widgets_manager->register_widget_type( new AStore_Widget_Latest_News );