'', 'thumb' => true, 'show' => 5 ); $instance = wp_parse_args( $instance, $defaults ); $instance = array_map( 'esc_attr', $instance ); ?>
/>
0)?$new_instance['show']:5; return $instance; } function widget($args, $instance) { // outputs the content of the widget extract( $args ); $defaults = array( 'title' => '', 'thumb' => true, 'show' => 5 ); $instance = wp_parse_args( $instance, $defaults ); $title = apply_filters( 'widget_title', $instance['title'] ); $posts = new WP_Query( array( 'no_found_rows' => 1, 'post_status' => 'publish', 'posts_per_page' => $instance['show'], 'ignore_sticky_posts' => true, 'no_found_rows' => true ) ); // caching! if ( $posts->have_posts() ) { // get posts thumbnails id's $images = array(); foreach ( $posts->posts as $p ) { if ( has_post_thumbnail( $p->ID ) ) { $images[] = get_post_thumbnail_id( $p->ID ); } } // get all images in once if ( $images ) { $i_query = new WP_Query( array( 'no_found_rows' => 1, 'posts_per_page' => -1, 'post_type' => 'attachment', 'post_status' => 'inherit', 'post__in' => $images ) ); } } echo $before_widget; if( $title ) echo $before_title . $title . $after_title; $last = $posts->found_posts; if( $posts->have_posts() ) { $i = 1; foreach( $posts->posts as $post_item ): $class = ''; if( $i == 1 ) { $class = ' first'; }elseif( $i == $last ) { $class = ' last'; } $title = get_the_title($post_item->ID); if( !$title ) { $title = __('No title', LANGUAGE_ZONE); } $img = ''; if ( $instance['thumb'] && has_post_thumbnail( $post_item->ID ) ) { $img_id = get_post_thumbnail_id( $post_item->ID ); $img_meta = wp_get_attachment_image_src( $img_id, 'full' ); // get alt $img_alt = get_post_meta( $img_id, '_wp_attachment_image_alt', true ); if ( !$img_alt ) { $img_alt = get_the_title( $post_item->ID ); } $img = dt_get_thumb_img( array( 'alt' => $img_alt, 'img_meta' => $img_meta, 'href' => get_permalink($post_item->ID), 'thumb_opts' => array('w' => 50, 'h' => 50) ), '