'widget-blogsquare-category-posts widget-posts-thumbnail', 'description' => __( 'Display posts in selected category', 'blogsquare' ) ); // Create the widget. parent::__construct( 'blogsquare-category-posts', // $this->id_base __( '» Category Posts', 'blogsquare' ), // $this->name $widget_options // $this->widget_options ); } /** * Outputs the widget based on the arguments input through the widget controls. * * @since 1.0.0 */ function widget( $args, $instance ) { // Default value. $defaults = array( 'title' => '', 'limit' => 6, 'show_number' => true ); $instance = wp_parse_args( (array) $instance, $defaults ); extract( $args ); // Output the theme's $before_widget wrapper. echo wp_kses_post( $before_widget ); // Theme prefix $prefix = 'blogsquare-'; // Pull the selected category. $cat_id = isset( $instance['cat'] ) ? absint( $instance['cat'] ) : 0; // Get the category. $category = get_category( $cat_id ); // Get the category archive link. $cat_link = get_category_link( $cat_id ); // Limit to category based on user selected tag. if ( ! $cat_id == 0 ) { $args['cat'] = $cat_id; } ?> ' . esc_html( $instance['title'] ). '' ); } elseif ( $cat_id == 0 ) { echo ( '

' . esc_html__( 'Recent Posts', 'blogsquare' ) . '

' ); } else { echo ( '

' . esc_attr( $category->name ) . '

' ); } ?> 'post', 'ignore_sticky_posts' => 1, 'post__not_in' => get_option( 'sticky_posts' ), 'posts_per_page' => $instance['limit'], 'cat' => $cat_id ); // The post query $wp_query = new WP_Query( $args ); // Store the transient. set_transient( 'blogsquare_category_posts_widget_' . $this->id, $wp_query ); $i = 1; if ( $wp_query->have_posts() ) : echo ''; ?> '', 'limit' => 6, 'cat' => '', 'show_number' => true ); $instance = wp_parse_args( (array) $instance, $defaults ); ?>

id="get_field_id( 'show_number' ) ); ?>" name="get_field_name( 'show_number' ) ); ?>" />