下载地址: http://wordpress.org/extend/plugins/wp-postviews/
WP-PostViews插件 用来统计一篇文章阅读次数,配合 WP-PostViews Widget 在侧边栏实现显示阅读次数最多的文章或者页面、某分类下阅读次数最多的文章等
启用以后,你仍然看不到效果,下面你找到wp-content/themes/你的主题/index.php(或者其他你要修改的文件如single.php,page.php等),找到这么一句代码:
<?php while (have_posts()) : the_post(); ?>
在后面合适的地方加上:
阅读次数:
< ?php 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、显示阅读次数最多的文章或页面
< ?php if (function_exists(‘get_most_viewed’)): ?>
< ?php get_most_viewed(); ?> < ?php endif; ?>
如果你只想显示越多次数最多的文章,用下面这句
< ?php if (function_exists(‘get_most_viewed’)): ?>
< ?php get_most_viewed(‘post’); ?> < ?php endif; ?>
如果你只想显示10篇阅读次数最多的文章,用下面的代码
< ?php if (function_exists(‘get_most_viewed’)): ?>
< ?php get_most_viewed(‘post’,10); ?> < ?php endif; ?>
get_most_viewed 函数的第一个参数决定要显示的类别,可选 post ,page,both,第二个参数决定要显示的篇数。
如果你想显示显示某类别下的阅读次数最多的文章,用下面这段
< ?php if (function_exists(‘get_most_viewed_category’)): ?>
< ?php get_most_viewed_category(the_catagory_ID(false)); ?>
< ?php endif; ?>
get_most_viewed_category函数有三个参数,第一个值是类别ID,第二个值是类别,可选both,page,post,第三个值决定要显示的篇数。
例如:显示分类ID为3下面阅读次数最多10篇文章
get_most_viewed_category(3, ‘post’, 10);

对《WP-PostViews》有1 条评论