__( 'A widget with collapsible feature which displays posts by authors. ', 'text_domain' ), ) // Args ); } public function widget( $args, $instance ) { // outputs the content of the widget global $wpdb; $title = $instance['title']; $limit_posts = ($instance['number']>0?$instance['number']:''); $display_excerpt = $instance['display_excerpt']; $html = '

'.$title.'

'; $table = $wpdb->prefix . 'users'; $users = $wpdb->get_results('SELECT ID FROM '.$table.' ORDER BY user_login'); if(!empty($users)){ foreach($users as $results){ $id = $results->ID; $user_info = get_userdata($id); $table = $wpdb->prefix . 'posts'; $result = $wpdb->get_results('SELECT * FROM '.$table.' WHERE post_author = '.$id.' AND post_status = "publish" AND post_type = "post" ORDER BY post_date DESC '.($limit_posts!=''?'LIMIT 0,'.$limit_posts:'')); $i = 0; if(!empty($result)){ $name = $user_info->first_name.' '.$user_info->last_name; //pree($user_info); $name = (trim($name)==''?ucwords($user_info->display_name):$name); $html .= '
'.$name.' ('.count($result).')'; $html .= '
'; } } } $html .= '
'; echo $html; } public function form( $instance ) { // outputs the options form on admin $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5; $excerpt = (isset( $instance['display_excerpt'] ) && $instance['display_excerpt'])==true ? true : false; ?>

/>