'amidstsky-recent-posts',
'description' => __( 'Widgte Displaying Recent Posts for Amidst Sky Theme', 'amidstsky')
);
parent::__construct( 'io-rp', __('Amidst Sky Recent Posts','amidstsky'), $widget_ops);
$this->alt_option_name = 'amidstsky-recent-posts';
add_action( 'save_post', array($this, 'flush_widget_cache') );
add_action( 'deleted_post', array($this, 'flush_widget_cache') );
}
public function widget($args, $instance) {
$cache = array();
if ( ! $this->is_preview() ) {
$cache = wp_cache_get( 'widget_recent_posts', 'widget' );
}
if ( ! is_array( $cache ) ) {
$cache = array();
}
if ( ! isset( $args['widget_id'] ) ) {
$args['widget_id'] = $this->id;
}
if ( isset( $cache[ $args['widget_id'] ] ) ) {
echo $cache[ $args['widget_id'] ];
return;
}
ob_start();
$title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recently Posted', 'amidstsky' );
/** This filter is documented in wp-includes/default-widgets.php */
$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
$number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 10;
/*if ( ! $number )
$number = 10;*/
$show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;
//$show_category = isset( $instance['show_category'] ) ? $instance['show_category'] : false;
$categories = get_categories();
$taxonomy = ( ! empty( $instance['taxonomy'] ) ) ? $instance['taxonomy'] : $categories;
$r = new WP_Query( apply_filters( 'widget_posts_args', array(
'posts_per_page' => $number,
'no_found_rows' => true,
'post_status' => 'publish',
'ignore_sticky_posts' => true,
'cat' => $taxonomy
) ) );
if ($r->have_posts()) :
?>
have_posts() ) : $r->the_post(); ?>
is_preview() ) {
$cache[ $args['widget_id'] ] = ob_get_flush();
wp_cache_set( 'widget_recent_posts', $cache, 'widget' );
} else {
ob_end_flush();
}
}
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['number'] = (int) $new_instance['number'];
$instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false;
//$instance['show_category'] = isset( $new_instance['show_category'] ) ? (bool) $new_instance['show_category'] : false;
$instance['taxonomy'] = $new_instance['taxonomy'];
$this->flush_widget_cache();
$alloptions = wp_cache_get( 'alloptions', 'options' );
if ( isset($alloptions['amidstsky-recent-posts']) )
delete_option('amidstsky-recent-posts');
return $instance;
}
public function flush_widget_cache() {
wp_cache_delete('widget_recent_posts', 'widget');
}
public function form( $instance ) {
$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
$number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 10;
$show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false;
//$show_category = isset( $instance['show_category'] ) ? (bool) $instance['show_category'] : false;
$taxonomy = isset( $instance['taxonomy'] ) ? esc_attr( $instance['taxonomy'] ) : '';
?>
" . get_the_date() . "";
} ?>
id="get_field_id( 'show_date' ); ?>" name="get_field_name( 'show_date' ); ?>" />