esc_html__( 'Latest posts.', 'blogable' ),
);
$this->default_title = __( 'Latest Posts & Pages', 'blogable' );
parent::__construct( 'widget_latest_posts', esc_html__( 'TP : Latest Posts', 'blogable' ), $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 = get_post_types( array( 'public' => true ) ) ;
unset( $allowed_post_types['attachment'] );
$allowed_post_types = array_values($allowed_post_types);
$types = isset( $instance['types'] ) ? (array) $instance['types'] : 'post';
?>
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 || 20 < $count ) {
$count = 20;
}
$ordering = isset( $instance['ordering'] ) && array('name', 'date') ? $instance['ordering'] : 'date' ;
/**
* 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' );
echo $args['before_widget'];
if ( ! empty( $title ) ) {
echo "";
}
$post_args = array(
'numberposts' => $count,
'post_type' => $types,
'category' => 0,
'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 || 20 < $instance['count'] ) {
$instance['count'] = 20;
}
if ( isset( $new_instance['ordering'] ) && in_array( $new_instance['ordering'], array( 'date', 'name' ) ) ) {
$instance['ordering'] = $new_instance['ordering'];
}else{
$instance['ordering'] = 'date';
}
$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 ] );
}
}
return $instance;
}
public static function defaults() {
return array(
'title' => esc_html__( 'Latest Posts', 'blogable' ),
'count' => absint( 5 ),
'types' => 'post',
'ordering' => 'date',
);
}
}
endif;