Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2012
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.61 KB | None | 0 0
  1.  */
  2. function my_list_authors_function($args = '') {
  3.     global $wpdb;
  4.  
  5.     $defaults = array(
  6.         'orderby' => 'name', 'order' => 'ASC', 'number' => '',
  7.         'optioncount' => false, 'exclude_admin' => true,
  8.         'show_fullname' => false, 'hide_empty' => true,
  9.         'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true,
  10.         'style' => 'list', 'html' => true
  11.     );
  12.  
  13.     $args = wp_parse_args( $args, $defaults );
  14.     extract( $args, EXTR_SKIP );
  15.  
  16.     $return = '';
  17.  
  18.     $query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number' ) );
  19.     $query_args['fields'] = 'ids';
  20.     $authors = get_users( $query_args );
  21.  
  22.     $author_count = array();
  23.     foreach ( (array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author") as $row )
  24.         $author_count[$row->post_author] = $row->count;
  25.  
  26.     foreach ( $authors as $author_id ) {
  27.         $author = get_userdata( $author_id );
  28.  
  29.         if ( $exclude_admin && 'admin' == $author->display_name )
  30.             continue;
  31.  
  32.         $posts = isset( $author_count[$author->ID] ) ? $author_count[$author->ID] : 0;
  33.  
  34.         if ( !$posts && $hide_empty )
  35.             continue;
  36.  
  37.         $link = '';
  38.  
  39.         if ( $show_fullname && $author->first_name && $author->last_name )
  40.             $name = "$author->first_name $author->last_name";
  41.         else
  42.             $name = $author->display_name;
  43.  
  44.         if ( !$html ) {
  45.             $return .= $name . ', ';
  46.  
  47.             continue; // No need to go further to process HTML.
  48.         }
  49.  
  50.         if ( 'list' == $style ) {
  51.             $return .= '<li>';
  52.         }
  53.  
  54.  
  55.         if ( !empty( $feed_image ) || !empty( $feed ) ) {
  56.             $link .= ' ';
  57.             if ( empty( $feed_image ) ) {
  58.                 $link .= '(';
  59.             }
  60.  
  61.             $link .= '<a href="' . get_author_feed_link( $author->ID ) . '"';
  62.  
  63.             $alt = $title = '';
  64.             if ( !empty( $feed ) ) {
  65.                 $title = ' title="' . esc_attr( $feed ) . '"';
  66.                 $alt = ' alt="' . esc_attr( $feed ) . '"';
  67.                 $name = $feed;
  68.                 $link .= $title;
  69.             }
  70.  
  71.             $link .= '>';
  72.  
  73.             if ( !empty( $feed_image ) )
  74.                 $link .= '<img src="' . esc_url( $feed_image ) . '" style="border: none;"' . $alt . $title . ' />';
  75.             else
  76.                 $link .= $name;
  77.  
  78.             $link .= '</a>';
  79.  
  80.             if ( empty( $feed_image ) )
  81.                 $link .= ')';
  82.         }
  83.        
  84.         $link = '<a href="' . get_author_posts_url( $author->ID, $author->user_nicename ) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $author->display_name) ) . '">' . $name . '</a>';
  85.        
  86.  
  87.         if ( $optioncount )
  88.             $link .= ' ('. $posts . ')';
  89.  
  90.         $return .= $link;
  91.         $return .= ( 'list' == $style ) ? '</li>' : ', ';
  92.     }
  93.  
  94.     $return = rtrim($return, ', ');
  95.  
  96.     if ( !$echo )
  97.         return $return;
  98.  
  99.     echo $return;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement