'editorial_block_column', 'description' => __( 'Display block posts as Column layout.', 'editorial' ) ); parent::__construct( 'editorial_block_column', __( 'Editorial: Block Posts (Column)', 'editorial' ), $widget_ops ); } /** * Helper function that holds widget fields * Array is used in update and form functions */ private function widget_fields() { $editorial_category_dropdown = editorial_category_dropdown(); $fields = array( 'editorial_block_title' => array( 'editorial_widgets_name' => 'editorial_block_title', 'editorial_widgets_title' => __( 'Block Title', 'editorial' ), 'editorial_widgets_field_type' => 'text' ), 'editorial_block_cat_id' => array( 'editorial_widgets_name' => 'editorial_block_cat_id', 'editorial_widgets_title' => __( 'Category for Block Post', 'editorial' ), 'editorial_widgets_default' => 0, 'editorial_widgets_field_type' => 'select', 'editorial_widgets_field_options' => $editorial_category_dropdown ), 'editorial_block_posts_count' => array( 'editorial_widgets_name' => 'editorial_block_posts_count', 'editorial_widgets_title' => __( 'No. of Posts', 'editorial' ), 'editorial_widgets_default' => 4, 'editorial_widgets_field_type' => 'number' ), ); return $fields; } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget( $args, $instance ) { extract( $args ); if( empty( $instance ) ) { return ; } $editorial_block_title = empty( $instance['editorial_block_title'] ) ? '' : $instance['editorial_block_title']; $editorial_block_cat_id = intval( empty( $instance['editorial_block_cat_id'] ) ? '' : $instance['editorial_block_cat_id'] ); $editorial_block_posts_count = intval ( empty( $instance['editorial_block_posts_count'] ) ? 4 : $instance['editorial_block_posts_count'] ); echo $before_widget; ?>
have_posts() ) { while ( $block_column_query->have_posts() ) { $block_column_query->the_post(); $post_count++; $post_id = get_the_ID(); if( $post_count == 1 ) { $post_class = 'primary-post'; $image_path = get_the_post_thumbnail( $post_id, 'editorial-block-medium' ); } else { $post_class = 'secondary-post'; $image_path = get_the_post_thumbnail( $post_id, 'editorial-block-thumb' ); } ?>

widget_fields(); // Loop through fields foreach ( $widget_fields as $widget_field ) { extract( $widget_field ); // Use helper function to get updated field values $instance[$editorial_widgets_name] = editorial_widgets_updated_field_value( $widget_field, $new_instance[$editorial_widgets_name] ); } return $instance; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. * * @uses editorial_widgets_show_widget_field() defined in widget-fields.php */ public function form( $instance ) { $widget_fields = $this->widget_fields(); // Loop through fields foreach ( $widget_fields as $widget_field ) { // Make array elements available as variables extract( $widget_field ); $editorial_widgets_field_value = !empty( $instance[$editorial_widgets_name] ) ? wp_kses_post( $instance[$editorial_widgets_name] ) : ''; editorial_widgets_show_widget_field( $this, $widget_field, $editorial_widgets_field_value ); } } }