How to Use Wordpress as a Membership Directory

UPDATE 5/26/08: I upgraded my membership directory to Wordpress version 2.5.1. There were little to no problems, so this tutorial is still completely valid for creating a membership directory with Wordpress.

UPDATE: This is a repost of a guest post I made earlier this year over at WPDesigner. I am reposting it here because of the neglect that has taken place recently over at WPDesigner. I will only be responding to questions on this article from now on. Thank you for your understanding. (FYI: My WPDesigner guest post was an unpaid one, so I am in no way stealing from anyone here…)

This article was written by Chris Cagle.

Do you want to create a moderated membership directory that showcases your member's information? Do you want it to be flexible, be very little work after initial setup, and use a world-class open source platform that you are already familiar with?

Your first thought might not be to use Wordpress for such a project, but since it already has an extremely easy way to accept, moderate and update registrations - it's a perfect candidate.

In this tutorial I will show you how I built a successful membership directory using nothing more than a standard Wordpress 2.3+ install and 2 very powerful plugins.

The Plugin Installs

The heart of the site is powered by two plugins.

First, use the WP User Manager plugin from Dealsway to add new fields to the user profiles. The install and setup is pretty straight forward - just activate the plugin and add any new fields you want via it’s own admin section. The information entered in these fields will become the information that will create the member's "homepage."

Secondly, we use the famous Role Manager plugin which restricts what your members can do once they are logged into your site. This is important because in order for a member to be granted their own author page, he or she needs to have made at least one post.

In my case, I didn't want my members to have the ability to post anything, just to only fill out their profile information. To get around this, I used the Role Manager plugin as-is, but changed the Author role to only have the rights Publish Posts and Read. (The Hide Dashboard capability you see in the screen shot is a function of the IWG Hide Dashboard plugin. It was an easy way to clean up the admin panel for my members.)

Setting Wordpress Options

After you have installed all the plugins, we need to get Wordpress ready for your new registrations.

In your Admin panel, under options, set your New User Default Role to Subscriber. This ensures that a member won't be given an author page until you "approve" and manually move them to the Author role. (A Subscriber can't make posts, an Author can.)

Once a member has registered and filled out all the appropriate profile information, we need to "approve" that member. We do this by simply moving that member into the Author role and making a post on his or her behalf. I want each approved member to have made a post in order to create the New Member Feed [example]. To post on behalf of that member, choose that member's name out of the dropdown list in the Post Author section in the sidebar before publishing their post.

This post doesn't need to be anything spectacular. On Pittsburgh Designers, I simply write "This business has been added as a member. Please visit their Design Profile."

There are other ways of doing this to make it slightly simpler, but I do it this way because I want to use Wordpress's default feed as a New Member Feed.

Your membership management duties are now done.

Creating the Author Page

All that's left now is the need to create the author.php template to display all this new member profile information that the WP User Manager plugin allowed us to accept.

For the sake of this tutorial, we only added 2 new fields to the member profile page: business_name and business_owner.

At the top of the author.php template we will add this code. Hint: Each new field you add will need to be declared here.

<?php
/*
Template Name: Author Template
*/
global $wp_query;
$curauth = $wp_query->get_queried_object();
$key="wpum_"."business_name";
$business_name = get_usermeta($curauth->ID, $key);
$key="wpum_"."business_owner";
$business_owner = get_usermeta($curauth->ID, $key);
?>

Now right below that, in the body section of your template, we are going to add this data and markup to display it in a structured way:

<?php get_header(); ?> 
<div id="bodycontent" > 
	<div class="bodytext" > 
		<h2><?php echo $business_name; ?></h2> 
		<p>The owner of this business is <?php echo $business_owner; ?></p> 
	</div> 
</div> 
<?php get_sidebar(); ?> 
<?php get_footer(); ?>

The next step is to also show some of the default fields that the member entered within their profile. I only want to show the member's website address and About the user section, so we modify our template to look like this:

<?php get_header(); ?>
<div id="bodycontent" >
	<div class="bodytext" >
		<h2><?php echo $business_name; ?></h2>
		<p>The owner of this business is <?php echo $business_owner; ?></p>
		<p>Website: <a href="<?php echo $curauth->user_url; ?>"><?php echo $curauth->user_url;?></a></p>
		<p>About the Business: <?php echo $curauth->description; ?></p>
	</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Hint: A full list of $curauth-> calls can be viewed in the Wordpress Codex.

Lastly, we want to do some basic error checking.

What would happen if the member didn't put anything in the business_owner field? In this case, we can just wrap that line in an if statement (…or any variable we want to protect against being blank):

<?php if ($business_owner != null) { echo "<p>The owner of this business is ".$business_owner."</p>"; }; ?>

Listing your Members

So how do you list all of your approved members? It is as simple as adding the wp_list_authors to any template file. This is the customized version of that function I use:

<?php
wp_list_authors('hide_empty=1&show_fullname=0&optioncount=0&exclude_admin=0'); 
?>

Tutorial Wrapup

This tutorial was based on my experiences in building the Pittsburgh Designers community into a thriving, local membership directory for creative types. Mosey on over to the site and take a peek for yourself how what a finished project like this can look like.

You can download the complete finished author.php template here.

About the Author

Chris Cagle is a freelance web designer from Pittsburgh, PA, whose projects include Pittsburgh Designers and AdClustr.

29 Reader Comments (reply)

  1. WordSkill said:

    Good luck with this Chris, I'm looking forward to seeing your 2.5 update - I've been reading up on the three plugins and, despite one or two reported glitches, they all seem to be basically okay under the current WordPress.

    My ultimate goal is to find a way for new members to create a post upon registration that gets put into the moderation queue; your example of how to slot the contents of custom fields into a template has given me hope that it might be possible - thanks for the inspiration.

  2. Graham said:

    Hello there … this reads very well and reminded me of what the guys at buddypress are doing !!! . Above however seems to be a simpler way and wondered if you or anyone out there has a link to a site that is essentially what you've explained above !!!

    Keep at it !!

  3. Graham said:

    other than the one above of course !!!

  4. Administrator

    May 6th, 2008

    5:15 pm

    Hey Graham - thanks for stopping by!

    I haven't been notified of anyone using an implemented version of the above (probably as WordSkill above points out that my tut was for WP 2.3). But saying that, I am not really sure that WP 2.5 should any issues with this.

    I would really love to see some directories using this as well….

  5. I would like to set-up our blog exactly like this to allow our readers to set-up profiles. The problem with this method is that I would have to accept every member and make them a page too. Not bad if you have a few members a day. But if you hope to get thousands of users then it becomes less practical. Could you think of a 'one click' solution where you approve someone and they automatically get their profile page?

  6. Administrator

    May 7th, 2008

    6:34 am

    @Boris - I looked at this, but I couldn't find a way to automatically generate a post from someone just by them registering, or otherwise. Of course, i only have a small membership (currently at ~106) so it wasn't that big of an issue for me.

    But then again, I think a system with thousands of members, maybe should be using a better equiped system than Wordpress. Maybe you can use a third party app to do this, and modify Wordpress to recognize their profiles on that app instead of the default WP one… just a thought…

  7. Claudio said:

    Hello Chris
    I check the pittsburg site and note that you put an image , i want to do the same, how i can do this? i visited the codex page and in the reference i dont see a metod to upload an show images..

  8. Administrator

    May 30th, 2008

    12:50 pm

    @Claudio - I upload those images manually myself so that I control the quality and size of them. I upload them to a folder on my site with a name that references their user ID - e.g 345.jpg

    After that, on the author.php page I add this code to show the image:

    <img src="http://yoursite.com/images/portfolio/<?php echo $curauth->ID; ?>.jpg" alt="" />

  9. Claudio said:

    thanks a lot for the reply¡¡
    saludos de Mexico

  10. Dave said:

    Hi Chris, great article. I'm busy trying to implement it on a site of my own but I've run into my first stumbling block.

    When I use User Manager, I can add/remove fields, but they only show up after the standard profile fields in the profile.php page, which I don't want. Did you edit your profile.php page's code directly or am I missing something?

    Thanks

  11. Administrator

    June 4th, 2008

    12:11 pm

    @Dave - You got it. I didn't put this in the tutorial because i thought it was just cosmetic in nature and not really necessary to get it up and running correctly.

    Good luck, it's one complicated php file.

  12. Dave said:

    thought so. I've taken a closer look at it and decided it's beyond me. Have you given any thought to my email request?

  13. Greg said:

    Chris,
    Thanks for posting this. I'm still new to php, so was wondering if you might be able to provide a little advice. I used your instructions to put together a freelancer directory for a regional science writers group. It looks fine, but I was wondering how might I put together a conditional statement (like the one you did for business_owner) for the URL? That is, some members don't have their own websites and I don't want a blank website to stand out.

    Everything I've done so far seems not to work. Thanks again.

  14. Administrator

    June 23rd, 2008

    11:04 am

    @Greg - Thanks! Here is the code:

    <?php if ($curauth->user_url != null) { ?>
    <a href="<?php echo $curauth->user_url; ?>"><?php echo $curauth->user_url; ?></a>
    <?php }; ?>

  15. Greg said:

    Chris,

    Thanks for the quick response. My problem now, I think, is that the default form has the "http://" part filled-in, so it will always list "http://"

    The answer must be in the user_edit file within wp_admin. Well, I know what I'm doing for lunch today. Thanks again Chris.

  16. Administrator

    June 23rd, 2008

    11:42 am

    @Greg, why does that field have to have http :// pre-filled in?

  17. Greg said:

    I think it comes that way, but I can't see how. It is really word. I'm bopping around user-edit.php and I just don't see it.

    Here's the bit in the table:

    <input type="text" name="url" id="url" value="user_url ?>" />

  18. Administrator

    June 23rd, 2008

    12:05 pm

    Greg, I am pretty sure that by default the web URL field is empty. I think this is the result of something you are doing on the author.php file. Did you try the code I left above?

  19. Greg said:

    The default assumption should be that I screwed up somewhere :)

    Thanks Chris, I'll let you know if I ever manage to fix it. My members have been clamoring for something like this for ages. If you ever make it to the other end of the state, I'll owe you a hoagie.

  20. Greg said:

    Chris, FYI. I think I found it in wp-admin/includes/user.php, where it was inserting "http://" if the field was left blank. I deleted it and it seemed to work.

  21. Administrator

    June 23rd, 2008

    12:28 pm

    Haha, deal!

    Great find - I had no idea it did that. Of course, I just thought of another solution - which may be better than hacking that user.php file (for when it comes time for the inevitable upgrade…)

    <?php if ($curauth->user_url != 'http://') { ?>
    <a href="<?php echo $curauth->user_url; ?>"><?php echo $curauth->user_url; ?></a>
    <?php }; ?>

  22. Christian said:

    I am having a problem pulling up a list under 2.5. Whenever I do, i keep getting

    Parse error: syntax error, unexpected '=' in /home/georgiau/public_html/site/wp-content/themes/gossip-theme/gossip/sponsors.php on line 13

    Any idea on whats causing this?
    Thanks!

  23. Administrator

    June 24th, 2008

    7:19 pm

    Christian - You are going to have to give me more than that for me to try and help…

  24. Chris, is there any plugin for members to upoad their portfolio without I have to manually upload the picture? :D

  25. Administrator

    June 25th, 2008

    12:28 pm

    @Arief - You could try UserPhoto. I didn't use it because it didn't work with WP 2.5 when I started this tutorial, but it looks like those issues have been resolved now…

  26. @Chris
    Thanks for your answer. It worked ini 2.5. I just want to let them upload picture by themselves. It needs an extra work to add more upload fields.

  27. Justin said:

    Hi Chris

    Thanks for this excellent post, it's just what I've been looking for.

    I've followed this guide step by step, but I seem to be having a problem with the Role Manager plugin. I thought the problem might be specific to Wordpress install 2.5.1 but I also tried it on another earlier version of WP 3.x and had the same problem.

    Both plugins (Role Manager and WP UserManager) install fine, and as the guide says I specify the Author role to only have the rights to Publish Posts and Read. I create a test post with admin using 'Author' as the Post Author. But when I log in as the newly created author, all I get is the profile page and access to the Dashboard. I can't edit or view the post created. As a quick test, I then tried to add additional privaliges to the author user, such as 'Edit Posts' and that worked ok (but obviously I don't want them to be able to create posts or view others).

    Any ideas as to why this is happening?

    (btw I'm running wordpress locally under MAMP on my macbook pro).

  28. Administrator

    July 1st, 2008

    10:42 am

    @Justin - Forgive me if I am reading your comment wrong, but this seems to be the way I intended it to work. I don't want the user to to be able to edit their post. I use it to generate the RSS feed for "new members" and I don't want the author to be able to change that one post.

    I would show you an example on the PghDesigners.com site, but it appears to be down - i really should look into that…

  29. Justin said:

    Hi Chris

    No you haven't read it wrong, it seems I've misunderstood your tutorial. Would there be a way I could enable them to only be able to edit that post. I suppose it beyond what Role Manager offers.

    I'm looking to create something like described in this post:-
    http://wordpress.org/support/topic/186060?replies=1#post-793968

    If you have time to read that, what approach would you suggest I take to achieve that. Been looking at various plugins and such but very much a wordpress newbie.

    Thanks

Post a Comment (rss)





Pittsburgh Web Design - Cagintranet Web Design