
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 作者信息框, and how to display 最近注册的用户. 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 函数.php file or in a 特定于站点的插件.
您需要做的第一件事是将以下代码复制并粘贴到主题的函数.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 数据库 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,则它将用户名链接到他们的网站。
接下来您需要做的是显示注册用户列表。为此,您需要做的就是在您想要显示用户列表的主题文件中添加以下代码行(例如 sidebar.php、footer.php 等)。
接下来,您需要显示注册用户的列表。为此,您需要做的就是在主题文件中添加以下几行代码,您将在其中显示用户列表(例如 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 小部件.
您还可以在帖子,页面或在小部件中使用此短代码显示站点中随机用户的列表。
[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 如何在 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 推特 and join us on 谷歌+
如果您有任何疑问或反馈,请在下面给我们留言。 另外,别忘了在在推特上关注我们并在谷歌+ 优越的加入我们
翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-randomly-display-registered-users-in-wordpress/
WordPress 用户注册