• Resolved Paola

    (@shotflamegmailcom)


    Hello,

    I found this awesome code that MichaelH provided for another user about a year ago to create a list of authors with avatar, user, and 3 most recent posts.

    <?php
    //displays all users with their avatar and 3 of their posts (titles)
    $blogusers = get_users_of_blog();
    if ($blogusers) {
      foreach ($blogusers as $bloguser) {
        $user = get_userdata($bloguser->user_id);
        echo '<p>User ID ' . $user->ID . ' ' . $user->user_firstname . ' ' . $user->user_lastname . '</p>';
        echo get_avatar( $user->ID, 46 );
        $args=array(
          'author' => $user->ID,
          'post_type' => 'post',
          'post_status' => 'publish',
          'posts_per_page' => 3,
          'caller_get_posts'=> 1
        );
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          //echo 'List of Posts for ' . user->user_firstname . ' ' . $user->user_lastname;
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
            <?php
          endwhile;
        }
      wp_reset_query();  // Restore global post data stomped by the_post().
      }
    }
    ?>

    Works like a charm! I was just wondering if it was possible to wrap each user’s information (avatar, name & recent post links) inside a DIV and the list of recent post links inside UL/LI tags? I’m a PHP newbie and I keep breaking my sidebar trying to figure this out. Any help is greatly appreciated, thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Here you go . . .

    <?php
    //displays all users with their avatar and 3 of their posts (titles)
    $blogusers = get_users_of_blog();
    if ($blogusers) {
      foreach ($blogusers as $bloguser) {
        $user = get_userdata($bloguser->user_id);
    	echo '<div id="single-user">';
        echo '<p>User ID ' . $user->ID . ' ' . $user->user_firstname . ' ' . $user->user_lastname . '</p>';
        echo get_avatar( $user->ID, 46 );
        $args=array(
          'author' => $user->ID,
          'post_type' => 'post',
          'post_status' => 'publish',
          'posts_per_page' => 3,
          'caller_get_posts'=> 1
    	);
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          //echo 'List of Posts for ' . user->user_firstname . ' ' . $user->user_lastname;
    	echo '<ul>';
    	while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
            <?php
          endwhile;
    	echo '</ul>';
    	echo '</div>';
    	}
      wp_reset_query();  // Restore global post data stomped by the_post().
      }
    }
    ?>
    Thread Starter Paola

    (@shotflamegmailcom)

    Works great! Thank you soooo much ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘authors listing, add DIV tag to PHP?’ is closed to new replies.