[WordPress] 外掛分享: WP-Stats

首頁外掛目錄 › WP-Stats
WordPress 外掛 WP-Stats 的封面圖片
2,000+
安裝啟用
★★☆☆☆
2.6/5 分(7 則評價)
13 天前
最後更新
問題解決
WordPress 6.8+ PHP 8.2+ v3.0.1 上架:2006-01-02

內容簡介

WP-Stats 外掛為您的部落格建立統計頁面,顯示文章、頁面、評論、標籤、分類及連結的數據,並提供最受歡迎的文章及評論者資訊,讓您輕鬆掌握網站狀況。

【主要功能】
• 一個短碼生成完整統計頁面
• 顯示文章、頁面、評論等總數
• 列出最受評論的文章及最新評論
• 提供每位評論者的評論列表
• 側邊欄小工具顯示總數
• 可單獨關閉每個區塊

外掛標籤

開發者團隊

⬇ 下載最新版 (v3.0.1) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「WP-Stats」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

WP-Stats builds a statistics page for your blog out of what is already in your database: how many posts, pages, comments, tags, categories and links there are, which posts drew the most comments, who has commented most often, and who writes for you. Put the [page_stats] shortcode on a page and that page becomes your statistics page. There is a sidebar widget for the totals, and the same statistics appear in wp-admin under WP-Stats.
Other plugins of mine can add their own blocks to that page. WP-Stats does not need to know anything about them in advance and never reads their settings.
Features

A full statistics page from one shortcode
Totals for posts, pages, comments, commenters, tags, categories, links and authors
Top X most commented posts and pages, most recent posts and most recent comments
A per-commenter view listing every comment somebody has left, with paging
A sidebar widget for the totals
Every block can be switched off individually

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.
Usage
Create The Stats Page

Go to WP-Admin -> Pages -> Add New
Type any title you like in the page’s title area
If you ARE using nice permalinks, WordPress will generate the permalink to the page after you type the title. You will see an ‘Edit’ link just beside the permalink.
Click ‘Edit’, type in stats in the text field and click ‘Save’.
Type [page_stats] in the page’s content area
Click ‘Publish’
If you ARE NOT using nice permalinks, go to WP-Admin -> WP-Stats, open the Settings tab and fill in ‘Stats URL’ with the URL of the page you just created.

The Block
Blog Statistics is in the editor’s inserter, under Widgets. Add it to a page and that page is your statistics page — there is nothing to configure on the block itself, because what the page shows comes from the settings and from whichever companion plugins are installed, not from the post.
It renders on the server, so the preview in the editor is the real page rather than an approximation, and the numbers are counted afresh on every view rather than frozen into the post when you save it.
The shortcode still works and is not going anywhere. [page_stats] behaves exactly as it always has, and a page already containing it needs no change. The block calls the same code the shortcode calls, so the two render identically — including the blocks other plugins contribute — and you can use whichever suits the page.
The Widget

Go to WP-Admin -> Appearance -> Widgets
The widget name is Stats.

For Plugin Authors
A plugin adds a block to the statistics page by answering one filter. Return an entry keyed by your own slug with underscores:
add_filter( 'wp_stats_sections', function ( $sections ) {
$options = get_option( 'my_plugin_options', array() );

if ( empty( $options['stats_display'] ) ) {
return $sections; // the site owner switched this block off
}

$sections['my_plugin'] = array(
'title' => __( 'My Plugin', 'my-plugin' ),
'priority' => 10,
'render' => 'my_plugin_render_stats',
);

return $sections;
} );

function my_plugin_render_stats() {
echo '

  • 42 things.

';
}

title is a translated heading and is required. `render` is a callable that echoes the block body, takes no arguments, and is required. `priority` sorts the blocks and defaults to 10; ties are broken by the array key.

Decide out of your own settings whether to contribute at all, and return $sections untouched if the answer is no rather than adding an entry with an empty body. WP-Stats never reads another plugin’s option row and never checks whether your classes exist — if your plugin is not installed, nothing answers the filter and no block appears.
WP-Stats then fires wp_stats_section_my_plugin with your entry. Its own listener on that action is what prints the heading and calls render, so a theme can take one plugin’s block over without disturbing the others:
add_action( 'wp_stats_section_my_plugin', function ( $section ) {
remove_action( 'wp_stats_section_my_plugin', array( 'WP_Stats_Page', 'render_section' ) );
echo '

drawn by the theme instead

';
}, 5 );

An entry that is malformed — not an array, no title, a render that is not callable — is skipped. It will not take the page down, and it will not tell you either, so check your block appears.

延伸相關外掛

文章
Filter
Mastodon