上午的时候磊子发布了WP-PostViews这个插件的中文版,有需要的可以了解一下。现在说一下这个文章统计插件的使用方法,这款插件需要我们手动添加代码。
首先是最常用的一种,你可以在你主题里面的archive.php, single.php, post.php 或者 page.php等等找到<?php while (have_posts()) : the_post(); ?>然后在它下面你需要显示的地方输入
| <?php if (function_exists( 'the_views' )) { the_views(); } ?> |
这样我们就可以在页面上显示出统计数量了。
另外一种情况就是不在主题的Loop循环中,我们想放在任意一个地方。这时候需要使用下面的这些方法。
1.最新浏览过的文章统计排行
| <?php if (function_exists( 'get_least_viewed' )): ?> |
| <?php get_least_viewed(); ?> |
| //* 第一个参数选择统计范围, 'post', 'page' or 'both'.文章,页面,全部 |
| //* 默认使用方法: get_least_viewed('both', 10); |
2.最受欢迎的文章统计(即:浏览次数最多的)排行
| <?php if (function_exists( 'get_most_viewed' )): ?> |
| <?php get_most_viewed(); ?> |
| //* 第一个参数选择统计范围, 'post', 'page' or 'both'.文章,页面,全部 |
| //* 默认使用方法: get_most_viewed('both', 10) |
3.最新浏览标签下的文章统计排行
| <?php if (function_exists( 'get_least_viewed_tag' )): ?> |
| <?php get_least_viewed_tag(); ?> |
| //* 第二个参数选择统计范围, 'post', 'page' or 'both'.文章,页面,全部 |
| //* 默认使用方法: get_least_viewed_tag(1, 'both', 10); |
4.浏览最多标签下的文章统计排行
| <?php if (function_exists( 'get_most_viewed_tag' )): ?> |
| <?php get_most_viewed_tag(); ?> |
| //* 第二个参数选择统计范围, 'post', 'page' or 'both'.文章,页面,全部 |
| //* 默认使用方法: get_most_viewed_tag(1, 'both', 10); |
5.显示最新浏览分类下的文章统计排行
| <?php if (function_exists( 'get_least_viewed_category' )): ?> |
| <?php get_least_viewed_category(); ?> |
| //* 第二个参数选择统计范围, 'post', 'page' or 'both'.文章,页面,全部 |
| //* 默认使用方法: get_least_viewed_category(1, 'both', 10); |
6.显示浏览最多分类下的文章统计排行
| <?php if (function_exists( 'get_most_viewed_category' )): ?> |
| <?php get_most_viewed_category(); ?> |
| //* 第二个参数选择统计范围, 'post', 'page' or 'both'.文章,页面,全部 |
| //* 默认使用方法: get_most_viewed_category(1, 'both', 10); |
7.根据浏览数量来进行排序
| <?php query_posts( 'v_sortby=views&v_orderby=desc' ) ?> |
| //v_orderby 排序的顺序 倒序(desc)和升序(asc) |
以上几点就是WordPress文章统计插件(WP-PostViews)使用方法了,大家可以根据自己的需要来选择对应的方法,如果有什么问题的可以联系磊子。
|