For people who run websites that allow people to register, especially a community type website, sometimes it might be a novel idea to list the most recent registered users in WordPress.
To do this, you must work a little PHP and WordPress database magic. For this code snippet tutorial, we’re bring in the user’s name, user’s profile link, and the user’s gravatar. The following code can be used in your theme template, or you can use a plugin like PHP Code Widget, that allows you to add PHP to your widgets.
<ul class="recent-registered-users"> <?php $usernames = $wpdb->get_results("SELECT user_nicename, user_url FROM $wpdb->users ORDER BY ID DESC LIMIT 5"); foreach ($usernames as $username) { echo '<li>' .get_avatar($username->comment_author_email, 45).'<a href="'.$username->user_url.'">'.$username->user_nicename."</a></li>"; } ?> </ul>
I’ve left this in an unordered list with it’s own CSS class so you can happily customize the CSS as you want. ๐ Also, you can alter the code to list more than 5.
As a note, if you don’t wish to mess around with code, you can also use the Recently Registered Widget plugin. This plugin gives you more options to display. It’s a little rough on the default design, but you could probably tweak it to suit your needs using some CSS magic. ๐
Pretty nifty, huh?
Leave a Reply