'kadence_image_grid', 'description' => __('This shows a grid of featured images from recent posts or portfolio items', 'ascend')); parent::__construct('kadence_image_grid', __('Ascend: Post Grid', 'ascend'), $widget_ops); } public function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base); if(isset($instance['orderby'])) { $orderby = $instance['orderby']; } else { $orderby = 'date'; } if($orderby == "menu_order" || $orderby == "title") { $order = "ASC"; } else { $order = "DESC"; } if(isset($instance['gridchoice'])) { $gridchoice = $instance['gridchoice']; } else { $gridchoice = 'post'; } if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) ) { $number = 8; } echo $before_widget; if ( $title ) echo $before_title . $title . $after_title; switch ($instance['gridchoice']) { case "portfolio" : $r = new WP_Query( apply_filters('widget_posts_args', array( 'post_type' => 'portfolio', 'portfolio-type' => $instance['thetype'], 'no_found_rows' => true, 'posts_per_page' => $number, 'post_status' => 'publish', 'orderby' => $orderby, 'order' => $order, 'ignore_sticky_posts' => true ) ) ); if ($r->have_posts()) : $image_size = apply_filters('ascend_widget_image_size', array('width'=> 60, 'height' => 60)); echo '
'; while ($r->have_posts()) : $r->the_post(); global $post; if(has_post_thumbnail( $post->ID ) ) { echo ''; echo ascend_get_full_image_output($image_size['width'], $image_size['height'], true, 'attachment-widget-thumb wp-post-image', null, null, true); echo ''; } endwhile; echo '
'; wp_reset_postdata(); endif; break; case "post": $r = new WP_Query( apply_filters('widget_posts_args', array( 'posts_per_page' => $number, 'category_name' => $instance['thecat'], 'no_found_rows' => true, 'orderby' => $orderby, 'order' => $order, 'post_status' => 'publish', 'ignore_sticky_posts' => true ) ) ); if ($r->have_posts()) : $image_size = apply_filters('ascend_widget_image_size', array('width'=> 60, 'height' => 60)); echo '
'; while ($r->have_posts()) : $r->the_post(); global $post; if(has_post_thumbnail( $post->ID ) ) { echo ''; echo ascend_get_full_image_output($image_size['width'], $image_size['height'], true, 'attachment-widget-thumb wp-post-image', null, null, true); echo ''; } endwhile; echo '
'; wp_reset_postdata(); endif; break; } echo $after_widget; } public function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = sanitize_text_field($new_instance['title']); $instance['number'] = (int) $new_instance['number']; $instance['thecat'] = sanitize_text_field($new_instance['thecat']); $instance['orderby'] = sanitize_text_field($new_instance['orderby']); $instance['thetype'] = sanitize_text_field($new_instance['thetype']); $instance['gridchoice'] = sanitize_text_field($new_instance['gridchoice']); return $instance; } public function form( $instance ) { $title = isset($instance['title']) ? esc_attr($instance['title']) : ''; $gridchoice = isset($instance['gridchoice']) ? esc_attr($instance['gridchoice']) : ''; $number = isset($instance['number']) ? absint($instance['number']) : 6; if (isset($instance['thecat'])) { $thecat = esc_attr($instance['thecat']); } else {$thecat = '';} if (isset($instance['thetype'])) { $thetype = esc_attr($instance['thetype']); } else {$thetype = '';} if (isset($instance['orderby'])) { $orderby = esc_attr($instance['orderby']); } else {$orderby = 'date';} $orderoptions = array(array('name' => 'Date', 'slug' => 'date'), array('name' => 'Random', 'slug' => 'rand'), array('name' => 'Comment Count', 'slug' => 'comment_count'), array('name' => 'Modified', 'slug' => 'modified'), array('name' => 'Menu Order', 'slug' => 'menu_order'), array('name' => 'Title', 'slug' => 'title')); $types= get_terms('portfolio-type'); $type_options = array(); $type_options[] = ''; if(!empty($types) && !is_wp_error($types) ) { foreach ($types as $type) { if ($thetype==$type->slug) { $selected=' selected="selected"';} else { $selected=""; } $type_options[] = ''; } } $categories= get_categories(); $cat_options = array(); $cat_options[] = ''; foreach ($categories as $cat) { if ($thecat==$cat->slug) { $selected=' selected="selected"';} else { $selected=""; } $cat_options[] = ''; } $order_options = array(); foreach ($orderoptions as $ooption) { if ($orderby==$ooption['slug']) { $selected=' selected="selected"';} else { $selected=""; } $order_options[] = ''; } ?>