WPTI.PS
WordPress Tips
  • Home
  • Functions
  • News
  • Plugins
  • Templates
  • CSS
  • Themes
  • Resources
  • About
Home » Templates » Creating a Member List
This post was written more than a year ago and might not be entirely accurate anymore.

← Pages with content and PHP code
Flexible way of grabbing first image from a Post →

Creating a Member List

15
Posted on February 27, 2010 in Templates
Creating a Member List

Recently we were asked to build a member list for a client. At first we thought that a list with just the names of the members of the choir would suffice, but the client actually wanted quite a bit more information!

Member ListApart from the names of the members the information per member should also have email address, home address, mobile phone number and date of birth. We suggested then also to add the gravatar image and if members don’t have one to add a default image.

Searching on the net for a solution for this, brings up with quite a few results, but none of them really worked well for us, because we had two more restrictions: the admin should be excluded and the members should be listed in alphabetical order and not on member-ID.

Finally we found the solution on Stephanie Leary’s SillyBean.net! Her solution shows the results in a table and also includes other stuff we didn’t need, so we adapted her code a bit to suit our specific needs.

<div class="member-list">
<!-- code adapted from fantastic sample of Stephanie Leary (http://sillybean.net/wordpress/templates/creating-a-user-directory-part-2-building-the-user-page-template/) -->
<?php
       $blogusers = get_users_of_blog(); //get all registered users
    foreach ($blogusers as $bloguser) {
		$user = get_userdata($bloguser->user_id); //get data about each user as an object
			// create a flat array with only the fields we need
			$allusers[$user->ID] = array(
				'last' => $user->last_name,
				'first' => $user->first_name,
				'nicename' => $user->user_nicename,
				'mobile' => $user->mobile,
				'email' => $user->user_email,
				'address' => $user->address,
				'bday' => $user->bday,
			);
	}
	asort($allusers);   // sort the users by last name
	?>
	<?php
	foreach ($allusers as  $auser) {
	            if ($auser['nicename'] != 'admin') { ?> //exclude the admin from the member list (change into what you use instead of admin)
               <p>
<?php echo get_avatar( $auser['email'], $size = '75', $default = 'http://image.url' ); ?>
<?php echo $auser['first']." ".$auser['last']." - ".$auser['email']; ?><br/>
               <?php echo $auser['address']; ?><br/>
               <?php echo $auser['mobile']; ?><br/>
               <?php echo $auser['bday']; ?></p>

	<?php } } ?>

</div><!--end member_list class-->

If you drop the code above in a Page template and give it a specific name, then you can call this template from within your WordPress Pages Editor. Keep in mind that you probably need to change the ‘nicename’ on line 22, unless you (still) use ‘admin’; if you want to call a default image, you need to change the URL on line 24.

And of course you will need to Change the Contact Info in the Users Profile. Good that we recently wrote a WordPress Tip on how to accomplish that!

  • +1
  • Tweet
  • Like
Shortlink to share or email this WP Tip to your friend(s):

Back to top ↑

← Pages with content and PHP code
Flexible way of grabbing first image from a Post →

  • WordPress
  • Google+

15 Responses to Creating a Member List

  1. Pingback: WordPress Tip: Change Contact Info in User Profile | WP TIPS

  2. Johnny said:
    April 27, 2010
    07:49hr

    Very useful. Creating a members list is a good idea. Thanks for sharing

  3. Bridget said:
    September 22, 2010
    01:37hr

    Are you using a specific membership plugin with the member directory you created for this site? I see that you have 4 pages or categories under members login “rehearsals, rules-regulations, directory, & documents”.

    Great post thanks!

    • wptips said:
      September 22, 2010
      10:42hr

      Hi Bridget, thanks for your comment.

      We are indeed using a specific membership plugin: Justin Tadlock’s Members. Lots of possibilities to add roles to different user groups!

      Under the members login we have 4 pages that can also contain sub-pages.

  4. Fask said:
    March 15, 2011
    03:12hr

    thanks for the tutorial but am having trouble with paginations, I see 10 people per page, but I do not know how I can continue, can you help?

    • wptips said:
      March 15, 2011
      08:37hr

      That’s strange indeed, it should show all members! Without being able to see your code, it’s quite impossible to say what could trigger this behaviour. Any chance that you can show it on pastebin or something?

      • Fask said:
        March 15, 2011
        17:05hr

        hello and sorry for my English, I explained badly. I would like 10 users per page, but I can not pagination to custom page? virtually all users can write articles on my site and list of contributors is long. You have a solution?

        • wptips said:
          March 15, 2011
          19:54hr

          ok, understand you now. You would have to find a way to include the call to pagination into the function. Maybe the Codex can help you further?

  5. Fask said:
    March 15, 2011
    20:07hr

    the problem is that they are expert in PHP and I do not know how …. would be really great if you wrote a tutorial about …

  6. Paul said:
    October 7, 2011
    11:05hr

    Is there a way to exclude two admins? I tried adding….

    if ($auser['nicename'] != ‘admin’) && $auser['nicename'] != ‘admin2′)

    …but it did not work

    • WPTIPS said:
      October 7, 2011
      14:09hr

      Have you tried to use || instead of &&? I also noticed that in your code above you use curly quotes instead of single quotes around admin, that could also be the problem…

      • Paul said:
        October 8, 2011
        01:33hr

        Thanks. I was not very clear, but using && in my customized code the first admin nicename is excluded just as it was before I added,the second condition, it is the second one that is being ignored. I did try a double pipe || but when using it neither name is excluded. In a past similar situation, && has worked just fine. I can’t figure out why it does not work here. I must be forgetting something.

        • WPTIPS said:
          October 8, 2011
          08:43hr

          Paul, pipes are used for OR, ampersands are used for AND, so if you want to use it in a conditional statement, I still think you should use pipes.

          Have you tried:
          ($auser['nicename'] != ‘admin’ || $auser['nicename'] != ‘admin2′)

          Another solution can be as described here: http://www.mattvarone.com/wordpress/list-users/#comment-1501

        • Dan Norris said:
          April 3, 2012
          06:45hr

          A little bit late, but for future reference
          Add the following code
          ‘id’ => $user->id,

          and then in your if statement write
          ($auser['id'] != ’4′ && $auser['id'] != ’1′)

          Of course replace the numbers with the users you wish to hide!

  7. Dan Norris said:
    April 3, 2012
    06:43hr

    Great bit of PHP that is coming in handy, I’ll post a link to the project that is using this code once it has gone live.
    For those who are looking at the above code, please note it can also be used in conjunction with custom user fields, to give your author cards thats extra little touch!

 WP TIPS on Google+

 RSS Links

  • Subscribe to WP TIPS by Email
  • All Tips
  • All comments

 WP TIPS Recommends

sponsor

sponsor

sponsor

sponsor

 Popular WP TIPS

  • Replace/Remove Default Header Image Twenty Eleven Theme
  • 4 ways on dealing with vendor prefixes
  • Replace Default Header Image Twenty Ten Theme
  • Make Your Own Latest News Dashboard Widget
  • Creating a Member List
  • How to add default custom background image WordPress 3.4?
  • Playing with Post Formats of WordPress 3.1
  • Extending the WordPress Walker Class
  • Multisite Dashboard Feed Widget plugin
  • WordPress 3.3 Dashboard Tweaks plugin

 Donations are Welcome!

I would like to donate

 Latest WP TIPS

    This post was written more than a year ago and might not be entirely accurate anymore.

  • Plugin Challenge
  • Prefix free by Lea Verou
  • Elegant Themes WPML compatible
  • Beijing WordPress Meetup Widget
  • Tip on how to add plugin directories to mu-plugins folder

WordPress Services

  • WordPress Consulting
  • WPML Assessment
  • Mobile Solutions
  • SEO & Social Media Strategy
  • Website Development
  • Managed WordPress Hosting

Go to top ↑

© Copyright 2013 · WP TIPS · Basejump WordPress Theme developed by Senlin Online · Powered by WordPress