Skip to toolbar

Step 5: Creating A List Of Users and Profile Page

Now it is time to create a user directory page on our page. This can be as simple as a list of names with links to author profile pages or a full fledged directory with all of the user’s information.

For our last step, we will create a custom page template to show a list of all users with links to their user profile pages. The simplest way to do this is with get_users. Create a new page template as a copy of page.php, and in place of the loop we will use WP_User_Query  to create a list of users, with their names as links to their user pages. Don’t forget to create a new page in WordPress using your new page template.

This simple function gets the users first and last names as well as the links to their profile pages and creates a list of links, ordered by last name. Click here for the complete user’s list template.

Here is where we are going to run into the problem I mentioned above about users without published posts. This may not be an issue for those of you who are using this to show contributors to your site. If you want to show profiles for users that are not authors of posts you will need to add a function to your theme’s function.php to show it. The content of this function is the same as the one we used in our author.php. In fact, you probably want to replace all of the identical code in author.php with a call to this function. Its one argument $user is intentionally identical to the variable $user we built in that step. Here is the complete function:

Once you’ve added that function you can use it in your users list template, like so:

Here is our new users list template and the updated author.php.

Continue to Step 6: Additional Options.