介绍一款功能型插件:readers_post。这款插件很实用,而且它的功能不只显示文章点击量,热门文章,最近浏览文章都能实现。如何使用,耕堂来解说:
1.先介绍下这款插件:
它的主要功能是展示文章的访问频繁程度,间接得反应受欢迎程度。点这里下载
2.插件具体功能:
1)显示访问数量
readers(’before’,’after’,display);
参数解释:
$before (string) => text posted before the number of visitors (optional)/*前缀(字符串)=>浏览量前的文本*/
$after (string) => text posted after the number of visitors (optional)/*后缀(字符串)=>浏览量后的文本*/
$display (boolean) => Shows the text (true, preset) or return just the value for using it in a different function of your php-code (false)/*显示(布尔)=>显示文本(1,预设)或返回使用的不同php代码函数值(0)*/
实例:
readers(’You are number ‘,’ reading this post’)=> “You are number 实际数 reading this post.”
调用方法:
<?php if(function_exists(’readers’)) {readers(’You are number ‘,’ reading this post’); } ?>
2)显示最近浏览文章
last_posts(number,letters,’before’,’after’);
参数解释:
$number (integer) => quantity of recent posts (default=5)/*文章数(整数)=>最近文章数(默认为5)*/
$letters (integer) => if for layout reasons it is necessary to shortened the title of your post this parameter sets the number of letters to be shown (default=0, which means: no abbreviation)/*字符数(整数)=>为了防止溢出,有必要设置文章标题的字符数*/
$before (string) => text posted before the number of visitors (optional)
$after (string) => text posted after the number of visitors (optional)
调用实例:
<?php if(function_exists(’last_posts’)) {last_posts(’8′,’50′); } ?>
3)点击量最多文章
hot_posts(number,letters,’before’,’after’);
参数解释:见2)参数解释
调用实例:
<?php if(function_exists(’hot_posts’)) {hot_posts(’8′,’50′); } ?>
以上这三个调用函数,可以放在任意地方,这里有原版英文解释.
右上方更多相关内容/站内搜索-关键词请用空格隔开
这个插件下下来就一个php文件吗?我按照上面的步骤做了:先复制这个php文件到plugins目录下然后再wp后台激活它,然后在我的single.php页面文章标题下加入了如下代码:
可是系统找不到readers这个函数,没输出(页面没啥变化),试了下结果还是没所以确定问题是找不到readers这个函数,我想问上面教的步骤中有没有少了哪个环节,期待回复ing
诶,上面代码怎么没贴上去,
恩,补充一下,我说的如下代码就是你上面的调用的代码
回复# Kevin不要把上面的代码完全复制,单引号是中文全角的,要改成英文半角的
恩,我是再英文半角状态下的输入单引号的
回复# 耕堂
这个插件是不是就一个php文件?
我的问题是在文件中需要的地方写入if(function_exists(readers)){echo ‘aaaa’;},他显示不出aaaa
回复# Kevin你不能这样写,这样:if(function_exists(readers)){readers(‘aaaa’,’aaa’);}或者if(function_exists(readers)){readers();}
昨天那个问题倒是解决了,if(function_exists(readers)){echo ‘aa’;}能输出东西了,可能是我之前插件装多了都开着冲突造成的,后来我全关了在开这个就行了,可现在又有新问题了,在插入语句的地方就显示这句:This post was read by 0 people until now,其中的数字不变,按理说应该是浏览一次就增1才对,就算有防刷新机制也应该加1的,我还不断的换本地ip试过也不行,就显示0,那说明应该是数据库操作没成功了
请达人帮俺分析分析,谢谢咯
哦,还有个问题,源代码里有个hot_posts_last函数在你文章里没作介绍,这个函数是干嘛的呀?
问题解决啦,是我后台登陆了以管理员的身份在浏览所以不行咯~~^_^
回复# Kevin
hot_posts_last,这个函数和hot_posts差不多,我也没试过,你可以测试一下,登陆后,确实是文章浏览不统计在内