__( 'A collection of post in a List', 'blog-postx' ) ]
);
}
public function widget( $args, $instance ) {
extract( $args );
$widget_title = ( isset( $instance['widget_title'] ) ) ? $instance['widget_title'] : '';
$number_of_posts_to_show = ( isset( $instance['number_of_posts_to_show'] ) ) ? $instance['number_of_posts_to_show'] : '';
$posts_categories = ( isset( $instance['post_catgories'] ) ) ? $instance['post_catgories'] : '';
$post_to_include = ( isset( $instance['post_to_include'] ) ) ? $instance['post_to_include'] : '';
$image_size = ( isset( $instance['image_size'] ) ) ? $instance['image_size'] : '';
$post_list_args = [
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => absint( $number_of_posts_to_show ),
'ignore_sticky_posts' => true
];
if( ! empty( $posts_categories ) ) $post_list_args['cat'] = $posts_categories;
if( ! empty( $post_to_include ) ) $post_list_args['post__in'] = explode( ',', $post_to_include );
echo wp_kses_post( $before_widget );
if( ! empty( $widget_title ) ) echo $before_title . $widget_title . $after_title;
$post_list_query = new \WP_Query( apply_filters( 'blog_postx_query_args_filter', $post_list_args ) );
if( $post_list_query->have_posts() ) :
$elementClass = 'post-list-wrap layout--one';
?>
have_posts() ) :
$post_list_query->the_post();
?>
term_id] = $category->name .'('. $category->count .')';
endforeach;
$category_list['type'] = 'category';
// for posts
$post_args = [
'post_type' => 'post',
'post_status'=> 'publish',
'posts_per_page' => -1
];
$posts_query = new \WP_Query( apply_filters( 'blog_postx_query_args_filter', $post_args ) );
if( $posts_query->have_posts() ) :
while( $posts_query->have_posts() ) :
$posts_query->the_post();
$post_list[ get_the_ID() ] = get_the_title();
endwhile;
endif;
$post_list['type'] = 'post';
wp_reset_postdata();
return [
[
'name' => 'widget_title',
'type' => 'text',
'title' => esc_html( 'Widget Title', 'blog-postx' ),
'description' => esc_html__( 'Add the widget title here', 'blog-postx' ),
'default' => esc_html__( 'Post List', 'blog-postx' )
],
[
'name' => 'post_catgories',
'type' => 'select-two',
'title' => esc_html__( 'Post Categories', 'blog-postx' ),
'description' => esc_html__( 'Choose the category to display list of posts', 'blog-postx' ),
'options' => $category_list
],
[
'name' => 'post_to_include',
'type' => 'select-two',
'title' => esc_html__( 'Post to Include', 'blog-postx' ),
'description' => esc_html__( 'Choose the posts to display in the list of posts', 'blog-postx' ),
'options' => $post_list
],
[
'name' => 'number_of_posts_to_show',
'title' => esc_html__( 'Number of posts to show', 'blog-postx' ),
'type' => 'number',
'default' => 3,
'max' => 6
],
[
'name' => 'image_settings_heading',
'type' => 'heading',
'label' => esc_html__( 'Image Settings', 'blog-postx' )
],
[
'name' => 'image_size',
'type' => 'select',
'title' => esc_html__( 'Image Size', 'blog-postx' ),
'options' => blog_postx_get_image_sizes_option_array(),
'default' => 'medium'
]
];
}
public function form( $instance ) {
$widget_fields = $this->widget_fields();
foreach( $widget_fields as $widget_field ) :
if( isset( $instance[ $widget_field['name'] ] ) ) :
$field_value = $instance[ $widget_field['name'] ];
elseif( isset( $widget_field['default'] ) ) :
$field_value = $widget_field['default'];
else:
$field_value = '';
endif;
blog_postx_widget_fields( $this, $widget_field, $field_value );
endforeach;
}
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$widget_fields = $this->widget_fields();
if( ! is_array( $widget_fields ) ) return;
foreach( $widget_fields as $widget_field ) :
$instance[ $widget_field['name'] ] = blog_postx_sanitize_widget_fields( $widget_field, $new_instance );
endforeach;
return $instance;
}
}