Advertisement
miriamdepaula

WordPress: Listando posts agrupados por autor

Sep 12th, 2011
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1. <?php
  2. $authors = $wpdb->get_results( $wpdb->prepare("SELECT ID, user_nicename from $wpdb->users WHERE 1=1 ORDER BY display_name") );
  3.          
  4.     if ( $authors ) {
  5.         foreach ( $authors as $author ) {
  6.           $user = get_userdata($author->ID);
  7.           $args=array(
  8.             'author' => $user->ID,
  9.             'post_type' => 'post',
  10.             'post_status' => 'publish',
  11.             'posts_per_page' => -1,
  12.             'caller_get_posts'=> 1
  13.           );
  14.              
  15.           $my_query = null;
  16.           $my_query = new WP_Query($args);
  17.          
  18.           if( $my_query->have_posts() ) {
  19.                
  20.             echo get_avatar( $user->ID, 46 ); //opcional
  21.                
  22.             echo '<h2>Posts de ' . $user->user_firstname . ' ' . $user->user_lastname . '</h2>';     
  23.                
  24.             echo '<ul>';
  25.                
  26.             while ($my_query->have_posts()) : $my_query->the_post();
  27.                  
  28.               echo '<li><a href="'. get_permalink() .'" rel="bookmark" title="Permanent Link to '. the_title_attribute('echo=0') .'">'. get_the_title(). '</a></li>';
  29.                  
  30.             endwhile;
  31.        
  32.             echo '</ul>';
  33.                
  34.           }
  35.              
  36.           wp_reset_query();
  37.          }
  38.       }
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement