如何在WordPress中显示实时在线用户

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
影片教学 (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

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

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

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视频教程。 您也可以在TwitterFacebook上找到我们。

翻译自: https://www.wpbeginner.com/plugins/how-to-show-real-time-online-users-in-wordpress/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
博客的人气在一天天的提升时,你是否想过统计下在线的访问量,当然,现在有很多统计工具,像CNZZ,51LA,Yahoo统计等等,都可以帮你实现这个功能,但是,还要登录到相关的统计站点,才能查看到相关信息,这对于一些博主来说,可能会有点麻烦,那么,看看这款插件吧。 WP-UserOnline插件可以显示在线用户.并可以统计用户浏览的页面,甚至于分析出是不是机器人正在访问你的网站.(这个功能实在有趣).当然,如果你不感觉到麻烦,你完全可以使用上面说的在线统计工具,那么这篇文章你也就没有看的必要了。O(∩_∩)O~ WP-UserOnline插件安装: 下载WP-UserOnline插件,将文件解压缩,上传到/wp-content/plugins/目录。 登录wordpress后台控制面板激活该插件,在“Settings”--->“Useronline”进行设置,其实,在页面也不需要什么特别的设置,当然,你可以修改Useronline的模板文件,这些如果你有兴趣的话,可以对其进行修改(点击浏览全图)。 WP-UserOnline插件使用: 一般应用(不带 Widget) 1、打开 /wp-content/themes/themes name/sidebar.php 2、添加以下代码到任意位置 <?php if (function_exists(’useronline’)): ?> <li> <h2>UserOnline</h2> <ul> <li><div id="useronline-count"><?php get_useronline(); ?></div></li> </ul> </li> <?php endif; ?> 一般应用(带 Widget) 1、激活 WP-UserOnline Widget 插件,登录到“WP-Admin -> Appearance-> Widgets” 2、找到UserOnline Widget,点击Add到侧边栏(sidebar),可以点击配置图标进行自定义设置 UserOnline Widget 然后保存就OK了。 建议不要使用这种方式,在测试的时候,激活该项后,博客侧栏的其它菜单都消失了,不知道什么原因,所以,建议您还是使用添加代码的方法进行添加。 添加好后,在后台左侧的上方的Dashboard的版块,会多出个WP-UserOnline链接,点击这个链接,它是显示当然在用户的信息,在这里你就会看到。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值