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

WordPress Stats View Counter

描述

Saves view counts from Jetpack Site Stats module as post meta data. This can be useful for displaying view counts in your theme and building custom queries.

What makes this a better solution over other view-tracking plugins is that it simply pulls the information from Jetpack, which is popular and provides fairly accurate data, so this has very little overhead. It’s a streamlined plugin that piggybacks off another which you might already be using.

Comes with a shortcode to display views and a filter to change the post meta key where views are saved.

Thank you to Milan Dinić for improvements in the code after the initial release (and for the Serbian translation)!

螢幕截圖

  • Settings

安裝

  1. Upload wp-stats-view-counter to the /wp-content/plugins/ directory.
  2. Activate the plugin through the Plugins menu in WordPress.
  3. Go to Settings > View Counter to select post types to track.
  4. Use shortcode [view-count] or get_post_meta( $post->ID, 'views', true ); to display views.

常見問題

Which post meta key is used?

By default views is the key where the view counts are saved, but you can filter this with the filter view_counter_meta_key. So for example, if you wanted to change the meta key from views to my-key, you would use this in your functions.php file:

add_filter( 'view_counter_meta_key', 'my_view_counter_meta_key', 10, 1 );

function my_view_counter_meta_key( $key ) {

    return 'my-key';

}

The plugin will check to make sure the new view count is greater than the old one before replacing, so there is some fallback to prevent it from overwriting previously saved views from other plugins also using the views post meta key.

How do I display the views?

Either using get_post_meta( $post->ID, 'views', true ); or the shortcode [view-count].

The shortcode can also accept before and after parameters, like so:

[view-count before="Views: "]
[view-count after=" views"]

And keep in mind that shortcodes can be activated using do_shortcode() if you have having troubled getting it to work:

echo do_shortcode( '[view-count]' );
How often does it update the views?

Every 3 hours an entry is accessed, the plugin will check the WordPress.com Stats view count and update locally. The delay is to ensure we don’t overload the WordPress.com Stats API.

This will be unnoticeable to the average visitor because it’s unlikely they are sitting on your site waiting for the views to update, like you might be.

Unless you have an extremely active site, there isn’t really much reason for the check to be more frequent.

Can I change the update time?

Yes, if you really want to, you can! Use the following filter:

add_filter( 'view_counter_transient_expiration', 'my_view_counter_transient_expiration', 10, 1 );

function my_view_counter_transient_expiration( $hours ) {

    return 2; // time in hours

}

評價

2016年9月3日 1 reply
Great, easy plug-in, showing views, if you have a jetpack. There were problems with compatibility with Wordpress 4.3.1, but the author has released a new version in which the problem is almost eliminated.
閱讀全部3個評價

貢獻者及開發者

“WordPress Stats View Counter” 是一個開源的軟體。以下的人對這個外掛作出了貢獻。

貢獻者

將 WordPress Stats View Counter 外掛本地化為台灣繁體中文版。

對開發相關資訊感興趣?

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

修改日誌

Version 1.3

  • Better handling on 404 pages
  • Minor improvements to code
  • Added more instructions about shortcode to readme

Version 1.2

Version 1.1

  • Thank you to Milan Dinić for all the improvements in this update!
  • Makes expiration time filterable, also makes sure that filter returns positive integer.
  • Changes one wrong text domain.
  • Wraps two strings with i18n function.
  • Uses number_format_i18n instead of number_format so that numbers are formatted for languages other than English too. Also makes sure that value passed to it is float since otherwise number_format will return error.
  • Pinking shears.

Version 1.0

  • This is version 1.0. Everything’s new!