'list_blog_pattern_widget', 'description' => 'This widget enables the list type blog pattern on the home page.', ); parent::__construct( 'list_blog_pattern_widget', 'List Blog Pattern', $widget_ops ); } /** * Outputs the content of the widget * * @param array $args * @param array $instance */ public function widget( $args, $instance ) { // outputs the content of the widget // print_var( $instance ); echo $args['before_widget']; if ( !empty( $instance['title'] ) ) { echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title']; } $_max = $instance['numb_post']; $instance['category']; $paged = (get_query_var( 'paged' )) ? get_query_var( 'paged' ) : 1; // WP_Query arguments $blog_args = array( 'post_type' => array( 'post' ), 'post_status' => array( 'publish' ), 'paged' => $paged, 'cat' => $instance['category'], 'posts_per_page' => $_max, ); $query = new WP_Query( $blog_args ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); get_template_part( 'templates/home', 'content-list-pattern' ); } } wp_reset_query(); echo $args['after_widget']; } /** * Outputs the options form on admin * * @param array $instance The widget options */ public function form( $instance ) { // outputs the options form on admin $title = !empty( $instance['title'] ) ? $instance['title'] : __( 'Blog Posts', 'andrina-lite' ); $numb_post = !empty( $instance['numb_post'] ) ? $instance['numb_post'] : 9; $category = !empty( $instance['category'] ) ? $instance['category'] : ''; // echo category; ?>

$this->get_field_name( 'category' ), 'selected' => $category ) ); ?>