Title: WP-PostViews
Author: Lester Chan
Published: <strong>2006 年 2 月 8 日</strong>
Last modified: 2025 年 8 月 31 日

---

搜索插件

![](https://ps.w.org/wp-postviews/assets/banner-772x250.jpg?rev=1206762)

![](https://ps.w.org/wp-postviews/assets/icon.svg?rev=978002)

# WP-PostViews

 作者：[Lester Chan](https://profiles.wordpress.org/gamerz/)

[下载](https://downloads.wordpress.org/plugin/wp-postviews.1.78.zip)

 * [详情](https://cn.wordpress.org/plugins/wp-postviews/#description)
 * [评价](https://cn.wordpress.org/plugins/wp-postviews/#reviews)
 * [开发进展](https://cn.wordpress.org/plugins/wp-postviews/#developers)

 [支持](https://wordpress.org/support/plugin/wp-postviews/)

## 描述

### 用法

 1. Open `wp-content/themes/<YOUR THEME NAME>/index.php`
 2. You may place it in archive.php, single.php, post.php or page.php also.
 3. Find: `<?php while (have_posts()) : the_post(); ?>`
 4. Add Anywhere Below It (The Place You Want The Views To Show): `<?php if(function_exists('
    the_views')) { the_views(); } ?>`
 5. Or you can use the shortcode `[views]` or `[views id="1"]` (where 1 is the post
    ID) in a post
 6. Go to `WP-Admin -> Settings -> PostViews` to configure the plugin.

### 开发

[https://github.com/lesterchan/wp-postviews/](https://github.com/lesterchan/wp-postviews/)

### 翻译

[http://dev.wp-plugins.org/browser/wp-postviews/i18n/](http://dev.wp-plugins.org/browser/wp-postviews/i18n/)

### 鸣谢

 * Plugin icon by [Iconmoon](http://www.icomoon.io) from [Flaticon](http://www.flaticon.com)

### Donations

I spent most of my free time creating, updating, maintaining and supporting these
plugins, if you really love my plugins and could spare me a couple of bucks, I will
really appreciate it. If not feel free to use it without any obligations.

### Version 1.76.1

 * NEW: Add Post Author in views template
 * NEW: Bump for WordPress 5.3

### Version 1.76

 * NEW: Added postviews_should_count filter
 * FIXED: Change to (int) from intval() and use sanitize_key() with it.

### Version 1.75

 * NEW: Use WP_Query() for most/least viewed posts

### Version 1.74

 * NEW: Bump WordPress 4.7
 * NEW: Template variable %POST_CATEGORY_ID%. It returns Post’s Category ID. If 
   you are using Yoast SEO Plugin, it will return the priority Category ID. Props
   @FunFrog-BY

### Version 1.73

 * FIXED: In preview mode, don’t count views

### Version 1.72

 * NEW: Add %POST_THUMBNAIL% to template variables

### Version 1.71

 * 修复：WordPress 4.3 中小工具构造函数中的通知

### Version 1.70

 * FIXED: Integration with WP-Stats

### Version 1.69

 * NEW: Shortcode `[views]` or [views id=”POST_ID”]` to embed view count into post
 * NEW: Added template variable `%VIEW_COUNT_ROUNDED%` to support rounded view count
   like 10.1k or 11.2M

### Version 1.68

 * NEW: Added action hook ‘postviews_increment_views’ and ‘postviews_increment_views_ajax’
 * NEW: Allow custom post type to be chosen under the widget

### Version 1.67

 * NEW: Allow user to not use AJAX to update the views even though WP_CACHE is true

### Version 1.66

 * NEW: Supports MultiSite Network Activation
 * NEW: Add %POST_DATE% and %POST_TIME% to template variables
 * NEW: Add China isearch engines bots
 * NEW: Ability to pass in an array of post types for get_most/least_*() functions.
   Props Leo Plaw.
 * FIXED: Moved uninstall to uninstall.php and hence fix missing nonce. Props Julio
   Potier.
 * FIXED: Notices and better way to get views from meta. Props daankortenbach.
 * FIXED: No longer needing add_post_meta() if update_post_meta() fails.

### Version 1.65 (02-06-2013)

 * FIXED: Views not showing in WP-Admin if “Display Options” is not set to “Display
   to everyone”

## 屏幕截图

 * [[
 * PostViews
 * [[
 * Admin – PostViews Options

## 常见问题

### How To View Stats With Widgets?

 * Go to `WP-Admin -> Appearance -> Widgets`
 * The widget name is Views.

### To Display Least Viewed Posts

    ```
    <?php if (function_exists('get_least_viewed')): ?>
        <ul>
            <?php get_least_viewed(); ?>
        </ul>
    <?php endif; ?>
    ```

 * The first value you pass in is the post type that you want. If you want to get
   every post types, just use ‘both’. It also supports PHP array: example `array('
   post', 'page')`.
 * The second value you pass in is the maximum number of post you want to get.
 * Default: get_least_viewed(‘both’, 10);

### To Display Most Viewed Posts

    ```
    <?php if (function_exists('get_most_viewed')): ?>
        <ul>
            <?php get_most_viewed(); ?>
        </ul>
    <?php endif; ?>
    ```

 * The first value you pass in is the post type that you want. If you want to get
   every post types, just use ‘both’. It also supports PHP array: example `array('
   post', 'page')`.
 * The second value you pass in is the maximum number of post you want to get.
 * Default: get_most_viewed(‘both’, 10);

### To Display Least Viewed Posts By Tag

    ```
    <?php if (function_exists('get_least_viewed_tag')): ?>
        <ul>
            <?php get_least_viewed_tag(); ?>
        </ul>
    <?php endif; ?>
    ```

 * The first value you pass in is the tag id.
 * The second value you pass in is the post type that you want. If you want to get
   every post types, just use ‘both’. It also supports PHP array: example `array('
   post', 'page')`.
 * The third value you pass in is the maximum number of post you want to get.
 * Default: get_least_viewed_tag(1, ‘both’, 10);

### To Display Most Viewed Posts By Tag

    ```
    <?php if (function_exists('get_most_viewed_tag')): ?>
        <ul>
            <?php get_most_viewed_tag(); ?>
        </ul>
    <?php endif; ?>
    ```

 * The first value you pass in is the tag id.
 * The second value you pass in is the post type that you want. If you want to get
   every post types, just use ‘both’. It also supports PHP array: example `array('
   post', 'page')`.
 * The third value you pass in is the maximum number of post you want to get.
 * Default: get_most_viewed_tag(1, ‘both’, 10);

### To Display Least Viewed Posts For A Category

    ```
    <?php if (function_exists('get_least_viewed_category')): ?>
        <ul>
            <?php get_least_viewed_category(); ?>
        </ul>
    <?php endif; ?>
    ```

 * The first value you pass in is the category id.
 * The second value you pass in is the post type that you want. If you want to get
   every post types, just use ‘both’. It also supports PHP array: example `array('
   post', 'page')`.
 * The third value you pass in is the maximum number of post you want to get.
 * Default: get_least_viewed_category(1, ‘both’, 10);

### To Display Most Viewed Posts For A Category

    ```
    <?php if (function_exists('get_most_viewed_category')): ?>
        <ul>
            <?php get_most_viewed_category(); ?>
        </ul>
    <?php endif; ?>
    ```

 * The first value you pass in is the category id.
 * The second value you pass in is the post type that you want. If you want to get
   every post types, just use ‘both’. It also supports PHP array: example `array('
   post', 'page')`.
 * The third value you pass in is the maximum number of post you want to get.
 * Default: get_most_viewed_category(1, ‘both’, 10);

### To Sort Most/Least Viewed Posts

 * You can use: `<?php query_posts( array( 'meta_key' => 'views', 'orderby' => '
   meta_value_num', 'order' => 'DESC' ) ); ?>`
 * Or pass in the variables to the URL: `http://yoursite.com/?v_sortby=views&v_orderby
   =desc`
 * 使用 ASC 替换 DESC 参数可以显示浏览次数最少的文章。

### 使用 LiteSpeed 缓存显示更新浏览数

Use: `<div id="postviews_lscwp"></div>` to replace `<?php if(function_exists('the_views')){
the_views(); } ?>`.
 NOTE: The id can be changed, but the div id and the ajax function
must match. Replace the ajax query in `wp-content/plugins/wp-postviews/postviews-
cache.js` with

    ```
    jQuery.ajax({
        type:"GET",
        url:viewsCacheL10n.admin_ajax_url,
        data:"postviews_id="+viewsCacheL10n.post_id+"&action=postviews",
        cache:!1,
        success:function(data) {
            if(data) {
                jQuery('#postviews_lscwp').html(data+' views');
            }
       }
    });
    ```

Purge the cache to use the updated pages.

### To Get Views With REST API

You can obtain the number of post views by adding `views` to your `_fields` parameter:
/
wp/v2/posts?_fields=views,title

## 评价

![](https://secure.gravatar.com/avatar/a6bd2ffefeab19f6b63b4bf213036879c37c226bc6dc43b32bd1aefd63fa3cf1?
s=60&d=retro&r=g)

### 󠀁[Useful plugin, but unique view counting by IP would be a great addition](https://wordpress.org/support/topic/useful-plugin-but-unique-view-counting-by-ip-would-be-a-great-addition/)󠁿

 [KR. Laboratories](https://profiles.wordpress.org/krashlab/) 2025 年 10 月 21 日

I’ve been using WP-PostViews for some time now, and it’s a very straightforward 
and effective plugin for displaying post views. The settings to count views only
from guests and exclude bots work well. However, I’ve noticed that if a guest refreshes
a page multiple times, each refresh is counted as a new view. While this is typical
behavior for a basic hit counter, it makes the view count less representative of
actual unique visitors. I would highly recommend considering an enhancement to include
an option to count unique views based on IP address (e.g., once per IP within a 
specified timeframe like 24 hours). This would significantly improve the accuracy
of the statistics and make the plugin even more valuable for site owners who want
to track genuine reader engagement. Thank you for this plugin!

![](https://secure.gravatar.com/avatar/eb107a34064b50d8474267f0f6868340edb106916e0836fa110e0d9b82f13e62?
s=60&d=retro&r=g)

### 󠀁[No longer works with Advanced Queries / Elementor](https://wordpress.org/support/topic/no-longer-works-with-advanced-queries-elementor/)󠁿

 [whitelabelcroydon](https://profiles.wordpress.org/whitelabelcroydon/) 2024 年 
4 月 26 日

Have been using this a while along side Advanced Queries and Elementors Loop widget
to display a list grid of most popular articles on a website. Doesnt seem to be 
working anymore. I think its still keeping count of the post views, but the views
template variable isnt pulling in the correct posts. From the posts it is showing
it looked like it stopped updating in January of this year. Will need to find another
solution!

![](https://secure.gravatar.com/avatar/d366ac4ddbadeab9be721eaf762279e0e5d3f19b1d60f5424926013d59437780?
s=60&d=retro&r=g)

### 󠀁[It doesn’t work with 6.5.2 wordpres version](https://wordpress.org/support/topic/it-doesnt-work-with-6-5-2-wordpres-version/)󠁿

 [sergio.pinna.prato](https://profiles.wordpress.org/sergiopinnaprato/) 2024 年 
4 月 21 日

It doesn’t work with 6.5.2 wordpres version.

![](https://secure.gravatar.com/avatar/e5f7b48fc5828047a785177445d5c23bd60340bd984b3cf46010f3bb441b3612?
s=60&d=retro&r=g)

### 󠀁[I guess this is no longer in supported](https://wordpress.org/support/topic/i-guess-this-is-no-longer-in-supported/)󠁿

 [Beulahland83](https://profiles.wordpress.org/beulahland83/) 2023 年 1 月 8 日

The plugin is no longer compatible with some themes example of (Corpo)

![](https://secure.gravatar.com/avatar/c017a834db5513b02da7e23515932225d4ff9d4441cd99291e92beff20e01058?
s=60&d=retro&r=g)

### 󠀁[very useful](https://wordpress.org/support/topic/very-useful-2967/)󠁿

 [douggeeks](https://profiles.wordpress.org/douggeeks/) 2022 年 3 月 23 日

Very useful little plugin.

![](https://secure.gravatar.com/avatar/277e3a55b0061c5b136b04acb20de33371ab3a0b23024de671d12570ddce961e?
s=60&d=retro&r=g)

### 󠀁[Awesome](https://wordpress.org/support/topic/awesome-9173/)󠁿

 [Ahmed Faruk](https://profiles.wordpress.org/ahmedfaruk/) 2021 年 12 月 6 日

This is the Plugin that I was looking for. Thanks a lot!

 [ 阅读所有65条评价 ](https://wordpress.org/support/plugin/wp-postviews/reviews/)

## 贡献者及开发者

「WP-PostViews」是开源软件。 以下人员对此插件做出了贡献。

贡献者

 *   [ Lester Chan ](https://profiles.wordpress.org/gamerz/)

「WP-PostViews」插件已被翻译至 18 种本地化语言。 感谢[所有译者](https://translate.wordpress.org/projects/wp-plugins/wp-postviews/contributors)
为本插件所做的贡献。

[帮助将「WP-PostViews」翻译成简体中文。](https://translate.wordpress.org/projects/wp-plugins/wp-postviews)

### 对开发感兴趣吗?

您可以[浏览代码](https://plugins.trac.wordpress.org/browser/wp-postviews/)，查看
[SVN仓库](https://plugins.svn.wordpress.org/wp-postviews/)，或通过[RSS](https://plugins.trac.wordpress.org/log/wp-postviews/?limit=100&mode=stop_on_copy&format=rss)
订阅[开发日志](https://plugins.trac.wordpress.org/log/wp-postviews/)。

## 更新日志

### Version 1.78

 * NEW: Add %POST_THUMBNAIL_URL% to template variables

### Version 1.77

 * NEW: Use Vanilla JS. Props @JiveDig
 * NEW: Bump to WordPress 6.2
 * NEW: Support views under fields for Rest API. Props @vitro-mod

## 额外信息

 *  版本 **1.78**
 *  最后更新：**9 月前**
 *  活跃安装数量 **100,000+**
 *  WordPress 版本 ** 4.0 或更高版本 **
 *  已测试的最高版本为 **6.8.5**
 *  语言
 * [Catalan](https://ca.wordpress.org/plugins/wp-postviews/) 、 [Chinese (China)](https://cn.wordpress.org/plugins/wp-postviews/)、
   [Chinese (Taiwan)](https://tw.wordpress.org/plugins/wp-postviews/) 、 [Dutch](https://nl.wordpress.org/plugins/wp-postviews/)、
   [English (UK)](https://en-gb.wordpress.org/plugins/wp-postviews/) 、 [English (US)](https://wordpress.org/plugins/wp-postviews/)、
   [French (France)](https://fr.wordpress.org/plugins/wp-postviews/) 、 [Galician](https://gl.wordpress.org/plugins/wp-postviews/)、
   [Greek](https://el.wordpress.org/plugins/wp-postviews/) 、 [Japanese](https://ja.wordpress.org/plugins/wp-postviews/)、
   [Persian](https://fa.wordpress.org/plugins/wp-postviews/) 、 [Russian](https://ru.wordpress.org/plugins/wp-postviews/)、
   [Spanish (Chile)](https://cl.wordpress.org/plugins/wp-postviews/) 、 [Spanish (Spain)](https://es.wordpress.org/plugins/wp-postviews/)、
   [Spanish (Venezuela)](https://ve.wordpress.org/plugins/wp-postviews/) 、 [Swedish](https://sv.wordpress.org/plugins/wp-postviews/)、
   [Tibetan](https://bo.wordpress.org/plugins/wp-postviews/) 、 [Ukrainian](https://uk.wordpress.org/plugins/wp-postviews/)
   和 [Vietnamese](https://vi.wordpress.org/plugins/wp-postviews/).
 *  [翻译成简体中文](https://translate.wordpress.org/projects/wp-plugins/wp-postviews)
 * 标签
 * [Counter](https://cn.wordpress.org/plugins/tags/counter/)[hits](https://cn.wordpress.org/plugins/tags/hits/)
   [postviews](https://cn.wordpress.org/plugins/tags/postviews/)[views](https://cn.wordpress.org/plugins/tags/views/)
 *  [高级视图](https://cn.wordpress.org/plugins/wp-postviews/advanced/)

## 评级

 4.4 星（最高 5 星）。

 *  [  48 条 5 星评价     ](https://wordpress.org/support/plugin/wp-postviews/reviews/?filter=5)
 *  [  8 条 4 星评价     ](https://wordpress.org/support/plugin/wp-postviews/reviews/?filter=4)
 *  [  1 条 3 星评价     ](https://wordpress.org/support/plugin/wp-postviews/reviews/?filter=3)
 *  [  1 条 2 星评价     ](https://wordpress.org/support/plugin/wp-postviews/reviews/?filter=2)
 *  [  7 条 1 星评价     ](https://wordpress.org/support/plugin/wp-postviews/reviews/?filter=1)

[Your review](https://wordpress.org/support/plugin/wp-postviews/reviews/#new-post)

[查看全部评论](https://wordpress.org/support/plugin/wp-postviews/reviews/)

## 贡献者

 *   [ Lester Chan ](https://profiles.wordpress.org/gamerz/)

## 支持

最近两个月解决的问题：

     总计 2，已解决 0

 [查看支持论坛](https://wordpress.org/support/plugin/wp-postviews/)

## 捐助

您愿意支持这个插件的发展吗?

 [ 捐助此插件 ](https://lesterchan.net/site/donation/)