widget_cssclass = 'cm-highlighted-posts'; $this->widget_description = esc_html__( 'Display latest posts or posts of specific category. Suitable for the Area Beside Slider Sidebar.', 'colormag' ); $this->widget_name = esc_html__( 'TG: Highlighted Posts', 'colormag' ); $this->settings = array( 'number' => array( 'type' => 'number', 'default' => 4, 'label' => esc_html__( 'Number of posts to display:', 'colormag' ), ), 'type' => array( 'type' => 'radio', 'default' => 'latest', 'label' => '', 'choices' => array( 'latest' => esc_html__( 'Show latest Posts', 'colormag' ), 'category' => esc_html__( 'Show posts from a category', 'colormag' ), 'tag' => esc_html__( 'Show posts from a tag', 'colormag' ), 'author' => esc_html__( 'Show posts from an author', 'colormag' ), ), ), 'category' => array( 'type' => 'dropdown_categories', 'default' => '', 'label' => esc_html__( 'Select category', 'colormag' ), ), ); parent::__construct(); } /** * Output widget. * * @param array $args Arguments. * @param array $instance Widget instance. * * @see WP_Widget */ public function widget( $args, $instance ) { global $post; $number = empty( $instance['number'] ) ? 4 : $instance['number']; $type = isset( $instance['type'] ) ? $instance['type'] : 'latest'; $category = isset( $instance['category'] ) ? $instance['category'] : ''; // Create the posts query. $get_featured_posts = $this->query_posts( $number, $type, $category ); $this->widget_start( $args ); ?>
have_posts() ) : $get_featured_posts->the_post(); ?>
the_post_thumbnail( $post->ID, $featured, 'cm-featured-image' ); } else { ?>
the_title(); // Displays the post meta. $this->entry_meta(); ?>
widget_end( $args ); } }