'image-stream', 'description' => esc_html__( 'Displays image thumbnails in a gallery-like format.', 'news' ) ); /* Set up the widget control options. */ $control_options = array( 'width' => 200, 'height' => 350 ); /* Create the widget. */ $this->WP_Widget( 'news-image-stream', // $this->id_base __( 'News: Image Stream', 'news' ), // $this->name $widget_options, // $this->widget_options $control_options // $this->control_options ); } /** * Outputs the widget based on the arguments input through the widget controls. * * @since 0.1.0 */ function widget( $sidebar, $instance ) { extract( $sidebar ); /* Output the theme's $before_widget wrapper. */ echo $before_widget; /* If a title was input by the user, display it. */ if ( !empty( $instance['title'] ) ) echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title; /* Query images. */ $loop = new WP_Query( array( 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_status' => 'inherit', 'posts_per_page' => intval( $instance['posts_per_page'] ), 'orderby' => 'parent' ) ); echo '
'; if ( $loop->have_posts() ) { while ( $loop->have_posts() ) { $loop->the_post(); echo wp_get_attachment_link( get_the_ID(), 'thumbnail', true ); } } else { echo '

' . __( 'There are currently no images found.', 'news' ) . '

'; } echo '
'; /* Close the theme's widget wrapper. */ echo $after_widget; } /** * Updates the widget control options for the particular instance of the widget. * * @since 0.1.0 */ function update( $new_instance, $old_instance ) { $instance = $new_instance; $instance['title'] = strip_tags( $new_instance['title'] ); $instance['posts_per_page'] = strip_tags( $new_instance['posts_per_page'] ); return $instance; } /** * Displays the widget control options in the Widgets admin screen. * * @since 0.1.0 */ function form( $instance ) { /* Set up the default form values. */ $defaults = array( 'title' => esc_attr__( 'Image Stream', 'news' ), 'posts_per_page' => 6, ); /* Merge the user-selected arguments with the defaults. */ $instance = wp_parse_args( (array) $instance, $defaults ); ?>