WordPress插件wp-postviews使用方法

      WP-PostViews 和 WP-PostViews Widget 是WordPress 2.7 默认提供的插件,闲来无事,把它启用,感觉没效果,Google一下,才明白它的用处,写出来供大家参考。

      WP-PostViews插件 用来统计一篇文章阅读次数,配合 WP-PostViews Widget 在侧边栏实现显示阅读次数最多的文章或者页面、某分类下阅读次数最多的文章等,当前版本1.31,支持WordPress 2.7。

      如果你下载的是WordPress 2.7中文版,后台默认会有这两个插件,直接启用即可,后台没有的,点这里官方下载,然后上传到wp-content/plugins/下面,然后在后台启用即可。

     启用以后,你仍然看不到效果,下面你找到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、显示阅读次数最多的文章或页面

1
2
3
< ?php if (function_exists('get_most_viewed')): ?>
< ?php get_most_viewed(); ?>
< ?php endif; ?>

如果你只想显示越多次数最多的文章,用下面这句

1
2
3
< ?php if (function_exists('get_most_viewed')): ?>
< ?php get_most_viewed('post'); ?>
< ?php endif; ?>

如果你只想显示10篇阅读次数最多的文章,用下面的代码

1
2
3
< ?php if (function_exists('get_most_viewed')): ?>
< ?php get_most_viewed('post',10); ?>
< ?php endif; ?>

get_most_viewed 函数的第一个参数决定要显示的类别,可选 post ,page,both,第二个参数决定要显示的篇数。

如果你想显示显示某类别下的阅读次数最多的文章,用下面这段

1
2
3
< ?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);
This entry was posted in Wordpress. Bookmark the permalink.

One Response to WordPress插件wp-postviews使用方法

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>