'widget_recent_progect_entries', 'description' => __( "The most recent Progects on your site", 'black-fusion') ); parent::__construct('recent-progects', __('Recent Progects', 'black-fusion'), $widget_ops); $this->alt_option_name = 'widget_recent_progect_entries'; 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') ); } function widget($args, $instance) { $cache = wp_cache_get('widget_recent_progects', '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(); extract($args); $widget_width = !empty($instance['widget_width']) ? $instance['widget_width'] : "widget-recent-progects"; /* Add the width from $widget_width to the class from the $before widget */ // no 'class' attribute - add one with the value of width if( strpos($before_widget, 'class') === false ) { $before_widget = str_replace('>', 'class="'. $widget_width . '"', $before_widget); } // there is 'class' attribute - append width value to it else { $before_widget = str_replace('class="', 'class="'. $widget_width . ' ', $before_widget); } $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Progects', 'black-fusion') : $instance['title'], $instance, $this->id_base); if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) ) $number = 10; $r = new WP_Query( apply_filters( 'widget_progects_args', array( 'post_type' => 'portfolio', 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true ) ) ); if ($r->have_posts()) : ?> have_posts() ) : $r->the_post(); ?> "")); ?> flush_widget_cache(); $alloptions = wp_cache_get( 'alloptions', 'options' ); if ( isset($alloptions['widget_recent_progect_entries']) ) delete_option('widget_recent_progect_entries'); return $instance; } function flush_widget_cache() { wp_cache_delete('widget_recent_progects', 'widget'); } function form( $instance ) { $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5; ?>