* @copyright Copyright (c) 2021, AeonWP * @link https://aeonwp.com/aeonblog * @license http://www.gnu.org/licenses/gpl-2.0.html * * AeonMag post Slider Widget * * @since 1.0.0 */ if (!class_exists('AeonMag_Latest_Post')) : /** * Highlight Post widget class. * * @since 1.0.0 */ class AeonMag_Latest_Post extends WP_Widget { private function defaults() { $defaults = array( 'title' => esc_html__('Latest Posts', 'aeonmag' ), 'cat' => 0, 'post-number' => 5, ); return $defaults; } function __construct() { $opts = array( 'classname' => 'aeonmag-latest-post', 'description' => esc_html__('Display lastest post and from category.', 'aeonmag'), ); parent::__construct('aeonmag-latest-post', esc_html__('AeonMag Latest Posts', 'aeonmag'), $opts); } function widget($args, $instance) { $instance = wp_parse_args( (array) $instance, $this->defaults() ); $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base); echo $args['before_widget']; if (!empty($title)) { echo $args['before_title'] . esc_html( $title ) . $args['after_title']; } $cat_id = !empty($instance['cat']) ? $instance['cat'] : ''; $post_number = !empty($instance['post-number']) ? $instance['post-number'] : ''; $query_args = array( 'post_type' => 'post', 'cat' => absint($cat_id), 'posts_per_page' => absint($post_number), 'ignore_sticky_posts' => true ); $query = new WP_Query($query_args); ?> have_posts()) : $i = 1; ?>
have_posts()) : $query->the_post(); ?>

defaults() ); ?>

'name', 'hide_empty' => 0, 'id' => $this->get_field_id('cat'), 'name' => $this->get_field_name('cat'), 'class' => 'widefat', 'taxonomy' => 'category', 'selected' => absint($instance['cat']), 'show_option_all' => esc_html__('Show Recent Posts', 'aeonmag') ); wp_dropdown_categories($cat_args); ?>