'widget_mfn_recent_posts', 'description' => __( 'The most recent posts on your site.', 'mfn-opts' ) );
parent::__construct( 'widget_mfn_recent_posts', __( 'Muffin Recent Posts', 'mfn-opts' ), $widget_ops );
$this->alt_option_name = 'widget_mfn_recent_posts';
}
/* ---------------------------------------------------------------------------
* Outputs the HTML for this widget.
* --------------------------------------------------------------------------- */
function widget( $args, $instance ) {
if ( ! isset( $args['widget_id'] ) ) $args['widget_id'] = null;
extract( $args, EXTR_SKIP );
echo $before_widget;
$title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base);
if( $title ) echo $before_title . $title . $after_title;
$args = array(
'posts_per_page' => $instance['count'] ? intval($instance['count']) : 0,
'no_found_rows' => true,
'post_status' => 'publish',
'ignore_sticky_posts' => true
);
if( $instance['category'] ) $args['category_name'] = $instance['category'];
$r = new WP_Query( apply_filters( 'widget_posts_args', $args ) );
$output = false;
if ($r->have_posts()){
$output .= '
';
$output .= '
';
$output .= '
'."\n";
}
echo $output;
echo $after_widget;
}
/* ---------------------------------------------------------------------------
* Deals with the settings when they are saved by the admin.
* --------------------------------------------------------------------------- */
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['count'] = (int) $new_instance['count'];
$instance['category'] = strip_tags( $new_instance['category'] );
return $instance;
}
/* ---------------------------------------------------------------------------
* 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'] ) : '';
$count = isset( $instance['count'] ) ? absint( $instance['count'] ) : 5;
$category = isset( $instance['category']) ? esc_attr( $instance['category'] ) : '';
?>