這個外掛並未在最新的 3 個 WordPress 主要版本上進行測試。開發者可能不再對這個外掛進行維護或提供技術支援,並可能會與更新版本的 WordPress 產生使用上的相容性問題。

WP-PostViews

外掛說明

使用方式

  1. 開啟 wp-content/themes/<目前使用的佈景主題代稱>/index.php
  2. You may place it in archive.php, single.php, post.php or page.php also.
  3. 搜尋 <?php while (have_posts()) : the_post(); ?>
  4. 在找到的程式碼下方 (任何想要顯示瀏覽量的位置),插入 <?php if(function_exists('the_views')) { the_views(); } ?>
  5. 或在文章中使用短代碼 [views][views id="1"] (1 代表文章 ID,這裡僅為示範用途)。
  6. 前往 [控制台]→[設定]→[瀏覽次數],便能為外掛進行設定。

開發資訊

GitHub 存放庫

語言套件

目前外掛的本地化進度

致謝

贊助開發工作

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

使用者評論

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!
2021 年 12 月 6 日
This is the Plugin that I was looking for. Thanks a lot!
2021 年 7 月 25 日
Very nice plugin, but I still have an advice that the view counter data should be saved in a new table. Now it was saved in “wp_postmeta”. Maybe it can be improved. Never mind, just my idea. Thanks!
閱讀全部 64 則使用者評論

參與者及開發者

以下人員參與了開源軟體〈WP-PostViews〉的開發相關工作。

參與者

〈WP-PostViews〉外掛目前已有 17 個本地化語言版本。 感謝全部譯者為這個外掛做出的貢獻。

將〈WP-PostViews〉外掛本地化為台灣繁體中文版

對開發相關資訊感興趣?

任何人均可瀏覽程式碼、查看 SVN 存放庫,或透過 RSS 訂閱開發記錄

變更記錄

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