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://zh-hk.wordpress.org/plugins/wp-postviews/#description)
 * [評價](https://zh-hk.wordpress.org/plugins/wp-postviews/#reviews)
 * [開發](https://zh-hk.wordpress.org/plugins/wp-postviews/#developers)

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

## 描述

### Usage

 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.

### Development

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

### Translations

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

### Credits

 * 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

 * FIXED: Notices in Widget Constructor for 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`
 * You can replace DESC with ASC if you want the least viewed posts.

### To Display Updating View Count With LiteSpeed Cache

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

## 其它

 *  Version **1.78**
 *  Last updated **8 個月之前**
 *  Active installations **100,000+**
 *  WordPress version ** 4.0 or higher **
 *  Tested up to **6.8.5**
 *  Languages
 * [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)
 * Tags
 * [Counter](https://zh-hk.wordpress.org/plugins/tags/counter/)[hits](https://zh-hk.wordpress.org/plugins/tags/hits/)
   [postviews](https://zh-hk.wordpress.org/plugins/tags/postviews/)[views](https://zh-hk.wordpress.org/plugins/tags/views/)
 *  [進階顯示](https://zh-hk.wordpress.org/plugins/wp-postviews/advanced/)

## 評分

 4.4 out of 5 stars.

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

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

[See all reviews](https://wordpress.org/support/plugin/wp-postviews/reviews/)

## 貢獻者

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

## 支援

有話想說？需要協助？

 [檢視支援論壇](https://wordpress.org/support/plugin/wp-postviews/)

## 捐贈

想要支援這個外掛的發展嗎？

 [ 贊助這個外掛 ](https://lesterchan.net/site/donation/)