esc_html__( 'Retrive Recent posts.', 'blogification' ), ); $this->default_title = __( 'Top Posts & Pages', 'blogification' ); parent::__construct( 'widget_trending_posts', esc_html__( 'TP : Recent Posts', 'blogification' ), $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; } $allowed_post_types = ['post', 'page', 'category']; $tp_category = isset( $instance['category'] ) ? absint( $instance['category'] ) : ''; $types = isset( $instance['types'] ) ? (array) $instance['types'] : 'post'; if ( isset( $instance['display'] ) && in_array( $instance['display'], array( 'widget_most_read_posts', 'widget_recent_news', 'widget_trending_posts' ) ) ) { $display = $instance['display']; } else { $display = 'widget_most_read_posts'; } ?>




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. */ $types = isset( $instance['types'] ) ? (array) $instance['types'] : array( 'post', 'page', 'category' ); if ( isset( $instance['display'] ) && in_array( $instance['display'], array( 'widget_most_read_posts', 'widget_recent_news', 'widget_trending_posts' ) ) ) { $display = $instance['display']; } else { $display = 'widget_most_read_posts'; } echo $args['before_widget']; if ( ! empty( $title ) ) { echo "
". $args['before_title'] . $title . $args['after_title'] . "
"; } $post_args = array( 'numberposts' => $count, 'post_type' => $types, 'category' => 0, 'orderby' => $ordering, 'order' => 'ASC', ); if( $category != '0' && in_array('category', $types) ){ $post_args = array( 'numberposts' => $count, 'post_type' => 'post', 'category' => (array) $category, 'orderby' => $ordering, 'order' => 'ASC', ); } $posts = get_posts( $post_args ); ?>

post_title; ?>

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'] = blogification_sanitize_single_category( $new_instance['category'] ); $allowed_post_types = get_post_types( array( 'public' => true ) ); unset( $allowed_post_types['attachment'] ); $allowed_post_types = array_values( $allowed_post_types ); $instance['types'] = $new_instance['types']; foreach ( $new_instance['types'] as $key => $type ) { if ( ! in_array( $type, $allowed_post_types ) ) { unset( $new_instance['types'][ $key ] ); } } if ( isset( $new_instance['display'] ) && in_array( $new_instance['display'], array( 'widget_most_read_posts', 'widget_recent_news', 'widget_trending_posts' ) ) ) { $instance['display'] = $new_instance['display']; } else { $instance['display'] = 'widget_most_read_posts'; } return $instance; } public static function defaults() { return array( 'title' => esc_html__( 'Widget Title ', 'blogification' ), 'count' => absint( 4 ), 'types' => 'post', 'ordering' => 'date', 'display' => 'widget_most_read_posts', 'category' => '0', ); } } endif; function blogification_recent_post_script_enqueue( $hook ) { wp_enqueue_script( 'blogification-metabox', get_template_directory_uri() . '/assets/js/metabox'. blogification_min() .'.js', array( 'jquery', 'jquery-ui-tabs' ), '20151215', true ); } add_action( 'admin_enqueue_scripts', 'blogification_recent_post_script_enqueue' );