__( ' displayed in Sidebar.', 'blog-vlog' ) )
);
}
public function widget( $args, $instance )
{
extract( $args );
if(!empty($instance)){
$title = apply_filters('widget_title', $instance['title'] );
$count = $instance['count'];
$order_by = $instance['order_by'];
echo $before_widget;
$output = '';
if ( $title )
echo $before_title . $title . $after_title;
global $post;
if ( $order_by == 'recent-post' )
{
$args = array(
'posts_per_page' => $count,
'order' => 'DESC'
);
}
else
{
$args = array(
'orderby' => 'comment_count',
'order' => 'DESC',
'posts_per_page' => $count
);
}
$posts_data = get_posts( $args );
if(count($posts_data)>0){
$output .='
';
foreach ($posts_data as $post): setup_postdata($post);
$output .='
';
endforeach;
wp_reset_postdata();
$output .='
';
}
echo $output;
echo $after_widget;
}
}
public function update( $new_instance, $old_instance )
{
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['order_by'] = strip_tags( $new_instance['order_by'] );
$instance['count'] = strip_tags( $new_instance['count'] );
return $instance;
}
public function form($instance ){
$defaults = array(
'title' => __('Latest Posts', 'blog-vlog'),
'order_by' => 'recent-post',
'count' => 5
);
$instance = wp_parse_args( (array) $instance, $defaults );
?>
__('Recent Posts', 'blog-vlog'),
'comments' => __('Most Commented Posts', 'blog-vlog' )
);
if(isset($instance['order_by'])) $order_by = $instance['order_by'];
?>