Forums

[resolved] Widget to display Users in a list (5 posts)

  1. Flutwerk
    Member
    Posted 2 years ago #

    Hello,

    I'm searching for a widget that lets you display users of your choice with their Profile Photo in a list.

    As I'm currently working on a film blog, I'd like to have the users which are members of the crew listed with their avatars -> in a sidebar.

    I can't seem to find any apropriate widget that does anything similar.

    Does anyone know a widget that might work? Or is there a way I could accomplish this without a widget, just in case?

    Thanks in advance
    Greetings

  2. MichaelH
    Volunteer
    Posted 2 years ago #

    This does more than you ask for but edit as needed.

    <?php
    //displays all users with their avatar and 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' => -1,
          '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().
      }
    }
    ?>

    Download and install Otto's PHP Code Widget, put that code in one of those widgets.

  3. Flutwerk
    Member
    Posted 2 years ago #

    Thank you Michael! That looks pretty much like what I was looking for.

    However I'd like to have their avatars displayed and next to it their names. This one does not display their usernames, but their ID's and posts, which is irelevant for me.

    Also this code simply lists every member whereas I'd like to be able to chose specific members (I only want to display certain members).

    I try to do this on my own and work at the code, but I'm a novice at PHP. If it's very easy to do that for someone who knows his/her way around, I'd really appreciate any help on this.

  4. MichaelH
    Volunteer
    Posted 2 years ago #

  5. Flutwerk
    Member
    Posted 2 years ago #

    Thanks! The combination of Otto's PHP Widget and the Author-Avatars Widget worked for me.

    The Author-Avatars Widget creates the PHP I needed and the PHP Widget displays it in the Sidebar!

Topic Closed

This topic has been closed to new replies.

About this Topic