
wordpress用户注册
Your users are the superstars of your multi-user WordPress site. There are many ways you can highlight users and authors on your site. Previously we showed you how to add an author info box, and how to display recently registered users. In this article, we will show you how to display a random list of registered users in WordPress.
您的用户是您的多用户WordPress网站的超级明星。 您可以通过多种方式突出显示网站上的用户和作者。 之前,我们向您展示了如何添加作者信息框 ,以及如何显示最近注册的用户 。 在本文中,我们将向您展示如何在WordPress中显示注册用户的随机列表。

First thing you need to do is copy and paste the following code in your theme’s functions.php file or in a site-specific plugin.
您需要做的第一件事是将以下代码复制并粘贴到主题的functions.php文件或特定于站点的插件中 。
function wpb_random_users() {
global $wpdb;
$randomusers = '<ul class="random-users">';
// Query database for users
$usernames = $wpdb->get_results("SELECT user_nicename, user_url, user_email FROM $wpdb->users ORDER BY RAND() LIMIT 5");
// Display users in a list
foreach ($usernames as $username) {
if (!$username->user_url) :
$randomusers .= '<li>' .get_avatar($username->user_email, 45) .$username->user_nicename."</li>";
else :
$randomusers .= '<li>' .get_avatar($username->user_email, 45).'<a href="'.$username->user_url.'">'.$username->user_nicename."</a></li>";
endif;
}
$randomusers .= '</ul>';
return $randomusers;
}
add_shortcode('randomusers','wpb_random_users');
This code queries the WordPress users table in your database and selects a random row, then it outputs the results in a bulleted list with user’s avatar and name. If a user has provided the website URL in their profile, then it will link the user name to their website.
此代码查询数据库中的WordPress用户表并选择一个随机行,然后将结果输出到带有用户的化身和姓名的项目符号列表中。 如果用户在其个人资料中提供了网站URL,则它将用户名链接到他们的网站。
Next thing you need to do is display the list of registered users. To do this, all you need to do is add the following line of code in your theme file where you want the user list to be displayed (such as sidebar.php, footer.php etc).
接下来,您需要显示注册用户列表。 为此,您需要做的就是在主题文件中添加以下代码行,以在其中显示用户列表(例如sidebar.php,footer.php等)。
<?php wpb_random_users(); ?>
You can also display a list of random users from your site using this shortcode in a post, page, or a widget.
您还可以在帖子,页面或窗口小部件中使用此短代码显示站点中随机用户的列表。
[randomusers]
[randomusers]
We hope this article helped you display a random list of registered users on your WordPress site. If you were looking to display a list of your staff members, then you should check out this tutorial on how to create a staff list in WordPress.
我们希望本文能帮助您在WordPress网站上随机显示注册用户列表。 如果您要显示工作人员列表,则应查看本教程, 了解如何在WordPress中创建工作人员列表 。
If you have any questions or feedback, then please leave us a comment below. Also don’t forget to follow us on Twitter and join us on Google+
如果您有任何疑问或反馈,请在下面给我们留言。 另外,别忘了在Twitter上关注我们并在Google+ 上加入我们
翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-randomly-display-registered-users-in-wordpress/
wordpress用户注册