'widget_duster_ephemera', 'description' => esc_html__( 'Use this widget to list your recent Aside, Status, Quote, and Link posts', 'duster' ) ) ); add_action( 'save_post', array(&$this, 'flush_widget_cache' ) ); add_action( 'deleted_post', array(&$this, 'flush_widget_cache' ) ); add_action( 'switch_theme', array(&$this, 'flush_widget_cache' ) ); } /** * Outputs the HTML for this widget. * * @param array An array of standard parameters for widgets in this theme * @param array An array of settings for this widget instance * @return void Echoes it's output **/ function widget( $args, $instance ) { $cache = get_transient( 'widget_' . $this->id ); if ( $cache ) { echo $cache; return; } ob_start(); extract( $args, EXTR_SKIP ); $title = apply_filters( 'widget_title', empty($instance['title']) ? esc_html__( 'Ephemera', 'duster' ) : $instance['title'], $instance, $this->id_base); if ( ! isset( $instance['number'] ) ) $instance['number'] = '10'; if ( ! $number = absint( $instance['number'] ) ) $number = 10; $ephemera_args = array( 'order' => 'DESC', 'posts_per_page' => $number, 'nopaging' => 0, 'post_status' => 'publish', 'post__not_in' => get_option( 'sticky_posts' ), 'tax_query' => array( array( 'taxonomy' => 'post_format', 'terms' => array( 'post-format-aside', 'post-format-link', 'post-format-status', 'post-format-quote' ), 'field' => 'slug', 'operator' => 'IN', ), ), ); $ephemera = new WP_Query(); $ephemera->query( $ephemera_args ); if ( $ephemera->have_posts() ) : echo $before_widget; echo $before_title; echo $title; // Can set this with a widget option, or omit altogether echo $after_title; global $post; ?>
    have_posts() ) : $ephemera->the_post(); ?> ID ) ) : ?>
  1. comments →', 'duster' ), __( '1 comment →', 'duster' ), __( '% comments →', 'duster' ) ); ?>
  2.   comments →', 'duster' ), __( '1 comment →', 'duster' ), __( '% comments →', 'duster' ) ); ?>
id, $cache ); } /** * Deals with the settings when they are saved by the admin. Here is * where any validation should be dealt with. **/ function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); $instance['number'] = (int) $new_instance['number']; $this->flush_widget_cache(); return $instance; } function flush_widget_cache() { delete_transient( 'widget_' . $this->id ); } /** * Displays the form for this widget on the Widgets page of the WP Admin area. **/ function form( $instance ) { $title = isset($instance['title']) ? esc_attr($instance['title']) : ''; $number = isset($instance['number']) ? absint($instance['number']) : 10; ?>