-postviews插件是用来统计每篇文章被小浏览次数,然后对其进行热门文章排行,可以实现阅读次数最多的文章或者页面,某分类下阅读次数最多的文章等功能,非常方便和强大。

wp- 安装非常简单,只要上传和激活即可。然后到 后台 > 设置 > 配置:

1.下载wp-postviews插件,并上传至wp-content/plugins目录下,然后登陆wordpress后台,启用该插件,这时设置选项卡下会生成一个PostViews选项和小工具中会生成一个Views工具.

2.点击设置选项卡下的PostsViews选项进入插件设置页面

(1)Count Views From:设置被统计的用户群

Everyone:所有人

Guests only:仅访客

Registered Users Only:仅注册用户

(2)Exclude Bot Views:是否排除机器人的浏览

YES:是

NO:不是

(3)Views Template:浏览量的显示格式

默认是:%VIEW_COUNT% views ,博客吧的是“热度%VIEW_COUNT% 度”,设置完如果想还原默认状态,可点击“Restore Default Template”恢复默认设置。

(4)Most Viewed Template:侧边栏 Widget 显示浏览量最多的文章(亦称“最受欢迎文章”)列表时的显示格式。

可用%VIEW_COUNT%、 %POST_TITLE%、%POST_EXCERPT%、%POST_CONTENT%、%POST_URL%对其进行参数设置。 默认设置:<li><a href=”%POST_URL%” title=”%POST_TITLE%”>%POST_TITLE%</a> – %VIEW_COUNT% views</li>

(5)Display Options:显示设置

Home Page(首页)、Singe Posts(文章页)、Pages(页面)、Archive Pages(分类归档页)、Search Pages(搜索页)、Other Pages(其它页面),可进行Display to everyone(所有人)、Display to registered users only(注册用户)、Don’t display on ***(不显示在***)选择

要让你的博客在页面上显示浏览次数,你需要修改你博客当前使用的主题:

1.打开wp-content/themes/<YOUR THEME NAME>/index.php,也可以放在archive.php,single.php,post.php或者page.php。

2.找到这行代码:

<?php while (have_posts()) : the_post(); ?>

3.然后在它下面的任何地方添加:

<?php if(function_exists(‘the_views’)) { the_views(); } ?>

(注意:网上有好多人这样写:<?php if(function_exists(‘the_views’)) { the_views(‘次’,true); } ?>,这样写就会在显示的浏览数多个1,所以代码不能这样写,插件的说明文件也只有上面的一种写法。)

方法一:通过widgets查看统计

如果当前WordPress主题支持widget(小工具)的话,可以在可用小工具中把Views小工具放到相应位置即可。

Statistics Type

least viewed:浏览最少的文章

least viewed by category:该分类下浏览最少的文章

most viewed:浏览最多的文章

most viewed by category:该分类下浏览最多的文章

Include Views From

posts & pages:显示文章和页面

posts only:只显示文章

pages only:只显示页面

方法二:在主题相应位置添加代码

显示阅读次数最多或最受欢迎的文章或页面:

<?php if (function_exists(‘get_most_viewed’)): ?> <ul> <?php get_most_viewed(); ?> </ul> <?php endif; ?>

显示阅读次数最多或最受欢迎的文章:

<?php if (function_exists(‘get_most_viewed’)): ?> <ul> <?php get_most_viewed(‘post’); ?> </ul> <?php endif; ?>

显示10篇阅读次数最多或最爱欢迎的文章:

<?php if (function_exists(‘get_most_viewed’)): ?> <ul> <?php get_most_viewed(‘post’,10); ?> </ul> <?php endif; ?>

说明:get_most_viewed 函数的第一个参数决定要显示的类别,可选 post ,page,both,第二个参数决定要显示的篇数。默认的是get_most_viewed(‘both’, 10);

显示文章阅读次数最少的文章或页面:

<?php if (function_exists(‘get_least_viewed’)): ?> <ul> <?php get_least_viewed(); ?> </ul> <?php endif; ?>

说明:get_least_viewed 函数的第一个参数决定要显示的类别,可选 post ,page,both,第二个参数决定要显示的篇数。默认的是get_most_viewed(‘both’, 10);

显示某分类下的阅读次数最多的文章:

<?php if (function_exists(‘get_least_viewed_category’)): ?> <ul> <?php get_least_viewed_category(); ?> </ul> <?php endif; ?>

说明:get_most_viewed_category函数有三个参数,第一个值是分类ID,显示分类,第二个值是类别,可选both,page,post,第三个值决定要显示的篇数。

显示某分类下的阅读次数最少的文章:

<?php if (function_exists(‘get_least_viewed_category’)): ?> <ul> <?php get_least_viewed_category(); ?> </ul> <?php endif; ?>

插件下载地址:

https://wordpress.org/plugins/wp-postviews/

发表评论

您的电子邮箱地址不会被公开。

− 1 = 4