'newsmag_slider', 'description' => __( 'You can add a fullwidth slider with this widget.', 'newsmag' ), 'customize_selective_refresh' => true ) ); } public function form( $instance ) { $defaults = array( 'title' => __( 'Recent posts', 'newsmag' ), 'newsmag_category' => 'uncategorized', 'order' => 'desc' ); $instance = wp_parse_args( (array) $instance, $defaults ); ?>
2 ); $atts['order'] = $args['order']; $atts['orderby'] = 'date'; if('rand' == $atts['order']){ $atts['order'] = ''; $atts['orderby'] = 'rand'; } if ( $idObj ) { $id = $idObj->term_id; $atts['cat'] = $id; } $posts = new WP_Query( $atts ); wp_reset_postdata(); return $posts; } /** * @param array $args * @param array $instance */ public function widget( $args, $instance ) { $defaults = array( 'title' => __( 'Recent posts', 'newsmag' ), 'newsmag_category' => '', 'order' => 'desc' ); $instance = wp_parse_args( (array) $instance, $defaults ); echo $args['before_widget']; $filepath = get_template_directory() . '/inc/libraries/widgets/widget-newsmag-homepage-slider/layouts/slider.php'; $posts = $this->get_posts( $instance ); if ( file_exists( $filepath ) ) { include $filepath; } else { esc_html_e( 'Please configure your widget', 'newsmag' ); } echo $args['after_widget']; } }