esc_html__( 'Displays latest posts or posts from a choosen category.Use this widget in the main sidebars.', 'hitmag' ), ) // Args ); } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. */ public function form( $instance ) { //print_r($instance); $defaults = array( 'title' => esc_html__( 'Latest Posts', 'hitmag' ), 'category' => 'all', 'number_posts' => 5, 'sticky_posts' => true, ); $instance = wp_parse_args( (array) $instance, $defaults ); ?>

$this->get_field_name('category'), 'selected' => $instance['category'], 'show_option_all' => 'Show all posts' ) ); ?>

class="checkbox" id="get_field_id('sticky_posts'); ?>" name="get_field_name('sticky_posts'); ?>" />

id_base ); $category = ( ! empty( $instance['category'] ) ) ? absint( $instance['category'] ) : 0; $number_posts = ( ! empty( $instance['number_posts'] ) ) ? absint( $instance['number_posts'] ) : 5; $sticky_posts = ( isset( $instance['sticky_posts'] ) ) ? $instance['sticky_posts'] : false; // Latest Posts $latest_posts = new WP_Query( array( 'cat' => $category, 'posts_per_page' => $number_posts, 'ignore_sticky_posts' => $sticky_posts ) ); echo $before_widget; ?>
have_posts() ) : ?> have_posts() ) : $latest_posts -> the_post(); ?>