esc_html__( 'Retrive Recent posts.', 'blogpost' ), ); $this->default_title = __( 'Top Posts & Pages', 'blogpost' ); parent::__construct( 'blogpost_popular_post', esc_html__( 'TP : Recent Posts', 'blogpost' ), $tp_widget_recent_post ); } function form( $instance ) { $instance = wp_parse_args( (array) $instance, $this->defaults() ); if ( false === $instance['title'] ) { $instance['title'] = $this->default_title; } $title = stripslashes( $instance['title'] ); $ordering = isset( $instance['ordering'] ) && array('name', 'date') ? $instance['ordering'] : 'date' ; $count = isset( $instance['count'] ) ? (int) $instance['count'] : 10; if ( $count < 1 || 10 < $count ) { $count = 10; } $tp_category = isset( $instance['category'] ) ? absint( $instance['category'] ) : ''; ?>




defaults() ); $title = isset( $instance['title'] ) ? $instance['title'] : false; if ( false === $title ) { $title = $this->default_title; } /** This filter is documented in core/src/wp-includes/default-widgets.php */ $title = apply_filters( 'widget_title', $title ); $count = isset( $instance['count'] ) ? (int) $instance['count'] : false; if ( $count < 1 || 10 < $count ) { $count = 5; } $ordering = isset( $instance['ordering'] ) && array('name', 'date') ? $instance['ordering'] : 'date' ; $category = isset( $instance['category'] ) ? (int) $instance['category'] : 0; /** * Control the number of displayed posts. * * @module widgets * * @since 3.3.0 * * @param string $count Number of Posts displayed in the Top Posts widget. Default is 10. */ echo $args['before_widget']; if ( ! empty( $title ) ) { echo "
". $args['before_title'] . $title . $args['after_title'] . "
"; } if( $category != '0' ){ $post_args = array( 'numberposts' => $count, 'post_type' => 'post', 'category' => (array) $category, 'orderby' => $ordering, 'order' => 'ASC', ); } $posts = get_posts( $post_args ); ?> default_title ) { $instance['title'] = false; // Store as false in case of language change } $instance['count'] = (int) $new_instance['count']; if ( $instance['count'] < 1 || 10 < $instance['count'] ) { $instance['count'] = 10; } if ( isset( $new_instance['ordering'] ) && in_array( $new_instance['ordering'], array( 'date', 'name' ) ) ) { $instance['ordering'] = $new_instance['ordering']; }else{ $instance['ordering'] = 'date'; } $instance['category'] = blogpost_sanitize_single_category( $new_instance['category'] ); return $instance; } public static function defaults() { return array( 'title' => esc_html__( 'Recent Posts ', 'blogpost' ), 'count' => absint( 4 ), 'types' => 'post', 'ordering' => 'date', 'category' => '0', ); } } endif;