'widget_popular_post',
'description' => esc_html__( 'Retrive Popular posts.', 'blogood' ),
);
$this->default_title = __( 'Top Posts & Pages', 'blogood' );
parent::__construct( 'blogood_popular_post', esc_html__( 'TP : Popular Posts', 'blogood' ), $tp_widget_popular_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 "";
}
if( $category != '' ){
$post_args = array(
'numberposts' => $count,
'post_type' => 'post',
'category' => (array) $category,
'orderby' => $ordering,
'order' => 'ASC',
);
}else{
$post_args = array(
'numberposts' => $count,
'post_type' => 'post',
);
}
$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'] = blogood_sanitize_single_category( $new_instance['category'] );
return $instance;
}
public static function defaults() {
return array(
'title' => esc_html__( 'Popular Posts ', 'blogood' ),
'count' => absint( 4 ),
'types' => 'post',
'ordering' => 'date',
'category' => '',
);
}
}
endif;