';
endwhile;
}
/**
* Adds post widgets: Recent, Popular, Related
* @since 1.2.0
*/
function a13fe_register_posts_widgets(){
class A13fe_Widget_Recent_Posts extends WP_Widget {
function __construct() {
$widget_ops = array( 'classname' => 'widget_recent_posts widget_about_posts',
'description' => esc_html__( 'The most recent posts on your site', 'apollo13-framework-extensions' )
);
parent::__construct( 'recent-posts', esc_html__( 'Apollo13Themes', 'apollo13-framework-extensions' ) . ' - ' . esc_html__( 'Recent Posts', 'apollo13-framework-extensions' ), $widget_ops );
$this->alt_option_name = 'widget_recent_entries';
add_action( 'save_post', array( &$this, 'flush_midget_cache' ) );
add_action( 'deleted_post', array( &$this, 'flush_midget_cache' ) );
add_action( 'switch_theme', array( &$this, 'flush_midget_cache' ) );
}
function widget( $args, $instance ) {
$before_widget = $after_widget = $before_title = $after_title = '';
$cache = wp_cache_get( 'widget_recent_entries', 'widget' );
if ( ! is_array( $cache ) ) {
$cache = array();
}
if ( isset( $cache[ $args['widget_id'] ] ) ) {
print $cache[ $args['widget_id'] ];
return;
}
ob_start();
extract( $args );
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? esc_html__( 'Recent Posts', 'apollo13-framework-extensions' ) : $instance['title'], $instance, $this->id_base );
if ( ! $number = absint( $instance['number'] ) ) {
$number = 10;
}
$r = new WP_Query( array( 'posts_per_page' => $number,
'no_found_rows' => true,
'post_status' => 'publish',
'ignore_sticky_posts' => true
) );
if ( $r->have_posts() ) :
print $before_widget;
if ( $title ) {
print $before_title . $title . $after_title;
}
a13fe_widget_posts( $r, $instance );
print $after_widget;
// Reset the global $the_post as this query will have stomped on it
wp_reset_postdata();
endif;
$cache[ $args['widget_id'] ] = ob_get_flush();
wp_cache_set( 'widget_recent_entries', $cache, 'widget' );
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['number'] = (int) $new_instance['number'];
$instance['content'] = isset( $new_instance['content'] );
$this->flush_midget_cache();
$alloptions = wp_cache_get( 'alloptions', 'options' );
if ( isset( $alloptions['widget_recent_entries'] ) ) {
delete_option( 'widget_recent_entries' );
}
return $instance;
}
function flush_midget_cache() {
wp_cache_delete( 'widget_recent_entries', 'widget' );
}
function form( $instance ) {
$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
$number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
?>