'blogmagazine_block_posts dg-clearfix', 'description' => esc_html__( 'Displays block posts from selected category in different layouts.', 'blogmagazine' ) ); parent::__construct( 'blogmagazine_block_posts', esc_html__( 'DG: Block Posts', 'blogmagazine' ), $widget_ops ); } /** * Helper function that holds widget fields * Array is used in update and form functions */ public function widget_fields( $instance = array() ) { $fields = array( 'dg_widget_tab' => array( 'dg_widget_field_name' => 'dg_widget_tab', 'dg_widget_field_title' => esc_html__( 'General', 'blogmagazine' ), 'dg_widget_field_default' => 'general', 'dg_widget_field_type' => 'tabgroup', 'dg_widget_field_options' => array( 'general'=>array( 'dg_widget_field_title'=>esc_html__('General', 'blogmagazine'), 'dg_widget_field_options'=> array( 'title' => array( 'dg_widget_field_name' => 'title', 'dg_widget_field_title' => esc_html__( 'Title', 'blogmagazine' ), 'dg_widget_field_description' => esc_html__( 'Enter your block title. (Optional - Leave blank to hide the title.)', 'blogmagazine' ), 'dg_widget_field_type' => 'text' ), 'title_target' => array( 'dg_widget_field_name' => 'title_target', 'dg_widget_field_wraper' => 'title-target', 'dg_widget_field_title' => esc_html__( 'Link Target', 'blogmagazine' ), 'dg_widget_field_default' => '_self', 'dg_widget_field_type' => 'select', 'dg_widget_field_options' => dglib_link_target(), 'dg_widget_field_relation' => array( 'exist' => array( 'show_fields' => array( 'title-link', ), ), 'empty' => array( 'hide_fields' => array( 'title-link', ), ), ), ), 'title_link' => array( 'dg_widget_field_name' => 'title_link', 'dg_widget_field_wraper' => 'title-link', 'dg_widget_field_title' => esc_html__( 'Title link', 'blogmagazine' ), 'dg_widget_field_default' => '', 'dg_widget_field_type' => 'text', ), 'terms_ids' => array( 'dg_widget_field_name' => 'terms_ids', 'dg_widget_field_title' => esc_html__( 'Block Category', 'blogmagazine' ), 'dg_widget_field_default' => 0, 'dg_widget_field_type' => 'multitermlist', 'dg_widget_taxonomy_type' => 'category', ), 'excerpt_length' => array( 'dg_widget_field_name' => 'excerpt_length', 'dg_widget_field_title' => esc_html__( 'Description Length', 'blogmagazine' ), 'dg_widget_field_default' => '100', 'dg_widget_field_type' => 'number', 'dg_widget_field_description' => esc_html__( 'Enter the short description length in character.', 'blogmagazine'), ), ) ), 'layout'=>array( 'dg_widget_field_title'=>esc_html__('Layout', 'blogmagazine'), 'dg_widget_field_options'=> array( 'block_layout' => array( 'dg_widget_field_name' => 'block_layout', 'dg_widget_field_title' => esc_html__( 'Block Layouts', 'blogmagazine' ), 'dg_widget_field_default' => 'layout1', 'dg_widget_field_type' => 'select', 'dg_widget_field_options' => array( 'layout1' => esc_html__( 'Layout 1', 'blogmagazine' ), 'layout2' => esc_html__( 'Layout 2', 'blogmagazine' ), 'layout3' => esc_html__( 'Layout 3', 'blogmagazine' ), 'layout4' => esc_html__( 'Layout 4', 'blogmagazine' ), ), ), 'largeimg_size' => array( 'dg_widget_field_name' => 'largeimg_size', 'dg_widget_field_title' => esc_html__( 'Large Image Size', 'blogmagazine' ), 'dg_widget_field_default'=> 'blogmagazine-thumb-622x420', 'dg_widget_field_type' => 'select', 'dg_widget_field_options' => dglib_get_image_sizes(), ), 'thumbnail_size' => array( 'dg_widget_field_name' => 'thumbnail_size', 'dg_widget_field_title' => esc_html__( 'Thumbnail Image Size', 'blogmagazine' ), 'dg_widget_field_default'=> 'blogmagazine-thumb-136x102', 'dg_widget_field_type' => 'select', 'dg_widget_field_options' => dglib_get_image_sizes(), ), ) ), ) ) ); $widget_fields_key = 'fields_'.$this->id_base; $widgets_fields = apply_filters( $widget_fields_key, $fields ); return $widgets_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 ; } /* * General Tab */ $title = isset( $instance['title'] ) ? esc_attr($instance['title']) : ''; $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); $title_link = isset( $instance['title_link'] ) ? esc_url($instance['title_link']) : ''; $title_target = isset( $instance['title_target'] ) ? esc_attr($instance['title_target']) : ''; $terms_ids = isset( $instance['terms_ids'] ) ? $instance['terms_ids'] : ''; $excerpt_length = isset( $instance['excerpt_length'] ) ? $instance['excerpt_length'] : 100; /* * Layout Tab */ $block_layout = isset( $instance['block_layout'] ) ? esc_attr($instance['block_layout']) : 'layout1'; $thumbnail_size = isset( $instance['thumbnail_size'] ) ? esc_attr($instance['thumbnail_size']) : 'thumbnail'; $largeimg_size = isset( $instance['largeimg_size'] ) ? esc_attr($instance['largeimg_size']) : 'full'; echo $before_widget; ?>