'smartline_category_posts_columns', 'description' => __('Display latest posts from two specified categories. Please use this widget ONLY on Frontpage Magazine widget area.', 'smartline-lite') ); $this->WP_Widget('smartline_category_posts_columns', __('Category Posts Columns (Smartline)', 'smartline-lite'), $widget_ops); // Delete Widget Cache on certain actions add_action( 'save_post', array( $this, 'delete_widget_cache' ) ); add_action( 'deleted_post', array( $this, 'delete_widget_cache' ) ); add_action( 'switch_theme', array( $this, 'delete_widget_cache' ) ); } public function delete_widget_cache() { wp_cache_delete('widget_smartline_category_posts_columns', 'widget'); } private function default_settings() { $defaults = array( 'title' => '', 'category_one' => 0, 'category_two' => 0, 'number' => 3, 'highlight_post' => true, 'category_titles' => false ); return $defaults; } // Display Widget function widget($args, $instance) { $cache = array(); // Get Widget Object Cache if ( ! $this->is_preview() ) { $cache = wp_cache_get( 'widget_smartline_category_posts_columns', 'widget' ); } if ( ! is_array( $cache ) ) { $cache = array(); } // Display Widget from Cache if exists if ( isset( $cache[ $this->id ] ) ) { echo $cache[ $this->id ]; return; } // Start Output Buffering ob_start(); // Get Sidebar Arguments extract($args); // Get Widget Settings $defaults = $this->default_settings(); extract( wp_parse_args( $instance, $defaults ) ); // Add Widget Title Filter $widget_title = apply_filters('widget_title', $title, $instance, $this->id_base); // Output echo $before_widget; ?>
is_preview() ) { $cache[ $this->id ] = ob_get_flush(); wp_cache_set( 'widget_smartline_category_posts_columns', $cache, 'widget' ); } else { ob_end_flush(); } } // Render Widget Content function render($args, $instance) { // Get Widget Settings $defaults = $this->default_settings(); extract( wp_parse_args( $instance, $defaults ) ); // Limit the number of words for the excerpt add_filter('excerpt_length', 'smartline_frontpage_category_excerpt_length'); ?>
__('All Categories', 'smartline-lite'),
'show_count' => true,
'hide_empty' => false,
'selected' => $category_one,
'name' => $this->get_field_name('category_one'),
'id' => $this->get_field_id('category_one')
);
wp_dropdown_categories( $args );
?>
__('All Categories', 'smartline-lite'),
'show_count' => true,
'hide_empty' => false,
'selected' => $category_two,
'name' => $this->get_field_name('category_two'),
'id' => $this->get_field_id('category_two')
);
wp_dropdown_categories( $args );
?>