Do you want to show the number of online users visiting your WordPress site? Online users widgets are fairly common for community sites and forums. In this article, we will show you how to display real time online users widget in WordPress.
您想显示访问您的WordPress网站的在线用户数量吗? 在线用户窗口小部件在社区站点和论坛中相当普遍。 在本文中,我们将向您展示如何在WordPress中显示实时在线用户小部件。
![Users online right now on a WordPress site Users online right now on a WordPress site](https://i-blog.csdnimg.cn/blog_migrate/15df141e02501c37a086053e5a1dec50.png)
影片教学 (Video Tutorial)
If you don’t like the video or need more instructions, then continue reading.
如果您不喜欢该视频或需要更多说明,请继续阅读。
First thing you need to do is install and activate the WP Useronline plugin. Upon activation, you need to visit Settings » UserOnline page to configure the plugin settings.
您需要做的第一件事是安装并激活WP Useronline插件。 激活后,您需要访问设置»UserOnline页面来配置插件设置。
![Users Online plugin settings Users Online plugin settings](https://i-blog.csdnimg.cn/blog_migrate/5fbf086885a0710a684605f140210ec0.png)
On this page, you can change the default plugin settings. These settings include time out, users online page URL, and display settings.
在此页面上,您可以更改默认插件设置。 这些设置包括超时,用户在线页面URL和显示设置。
The default settings would work for most sites, so you need to just click on the save settings button at the bottom of the page.
默认设置适用于大多数网站,因此您只需单击页面底部的“保存设置”按钮。
The next step is to create the page where you want to showcase the users who are online right now on your WordPress site. Create a new WordPress page by going to Pages » Add New.
下一步是创建一个页面,您要在其中显示WordPress网站上当前在线的用户。 转到页面»添加新页面,创建一个新的WordPress页面。
You can use any title for the page, but the page’s URL slug should be the same as you had in the plugin’s settings. Click on the edit button next to the URL slug and change it to useronline.
您可以为页面使用任何标题,但是页面的URL段应该与插件设置中的相同。 单击URL链接旁边的编辑按钮,然后将其更改为useronline。
![Edit page slug to useronline Edit page slug to useronline](https://i-blog.csdnimg.cn/blog_migrate/148c20669832d81cfe14d0499c79a633.png)
After that you need to add the shortcode [page_useronline]
in the content area. You can now publish this page.
之后,您需要在内容区域中添加简码 [page_useronline]
。 您现在可以发布此页面。
在WordPress前端显示在线用户 (Displaying Online Users on the Front-end in WordPress)
The plugin provides two ways to display online users on your WordPress site. The first method is recommended for beginners. Simply go to Appearance » Widgets page. Next, drag and drop User Online widget from the list of available widgets to a sidebar.
该插件提供了两种在WordPress网站上显示在线用户的方式。 建议初学者使用第一种方法。 只需转到外观»小部件页面。 接下来,将“用户在线”窗口小部件从可用窗口小部件列表拖放到侧边栏。
![Users online widget Users online widget](https://i-blog.csdnimg.cn/blog_migrate/21d47cee03eaf70d423ec2e75ea97bf5.png)
The other method is to use this code in your theme files where you want to display users online.
另一种方法是在您要在线显示用户的主题文件中使用此代码。
<?php if (function_exists('users_online')): ?>
<p>Users online: <div id="useronline-count"><?php users_online(); ?></div></p>
<?php endif; ?>
Using the second method will allow you to use custom CSS to style it differently.
使用第二种方法将允许您使用自定义CSS对其进行不同的样式设置。
We hope this article helped you display the number of online users on your WordPress site. You may also want to take a look at out tutorial on how to add a private messaging system to your WordPress site.
我们希望本文能帮助您显示WordPress网站上的在线用户数量。 您可能还想看看有关如何向WordPress网站添加私人消息传递系统的教程。
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
如果您喜欢这篇文章,请订阅我们的YouTube频道 WordPress视频教程。 您也可以在Twitter和Facebook上找到我们。
翻译自: https://www.wpbeginner.com/plugins/how-to-show-real-time-online-users-in-wordpress/