Wordpress插件wp-postviews及wp-postviews widget使用方法
WP-PostViews插件是用来统计一篇文章阅读次数,配合 WP-PostViews Widget 在侧边栏实现显示阅读次数最多的文章或者页面、某分类下阅读次数最多的文章等,当前版本1.50,支持WordPress 2.7。
如果你下载的是WordPress 2.7中文版,后台默认会有这两个插件,直接启用即可,后台没有的,点这里去下载1.31版,然后上传到wp-content/plugins/下面,然后在后台启用即可。
启用以后,你仍然看不到效果,下面你找到wp-content/themes/你的主题/index.php(或者其他你要修改的文件如single.php,page.php等),找到这么一句代码:
while (have_posts()) : the_post();
在后面合适的地方加上:
阅读次数:
if(function_exists('the_views')) { the_views(); }
即可,恭喜你WP-PostViews插件已成功启用。下面介绍WP-PostViews Widget 插件的使用。
首先你先确认的WP-PostViews 和 WP-PostViews Widget插件已经启用,如果你使用的主题支持Widget,在菜单外观下面点Widget进去,然后点添加,拖动wp-postviews Widget 到合适的位置即可。如果不支持,没关系,打开你的sidebar.php,把下面代码加到合适的地方。
1、显示阅读次数最多的文章或页面
if (function_exists('get_most_viewed')):
get_most_viewed();
endif;
如果你只想显示越多次数最多的文章,用下面这句
if (function_exists('get_most_viewed')):
get_most_viewed('post');
endif;
如果你只想显示10篇阅读次数最多的文章,用下面的代码
if (function_exists('get_most_viewed')):
get_most_viewed('post',10);
endif;
get_most_viewed 函数的第一个参数决定要显示的类别,可选 post ,page,both,第二个参数决定要显示的篇数。
如果你想显示显示某类别下的阅读次数最多的文章,用下面这段
if (function_exists('get_most_viewed_category')):
get_most_viewed_category(the_catagory_ID(false));
endif;
get_most_viewed_category函数有三个参数,第一个值是类别ID,第二个值是类别,可选both,page,post,第三个值决定要显示的篇数。
例如:显示分类ID为3下面阅读次数最多10篇文章
get_most_viewed_category(3, 'post', 10);
一朋友也写了一篇这样的文章 不妨去看看 http://www.stuseo.com/index.php/wp-postviews-installation-guide