
內容簡介
WP Most Popular 是一個應付排名部落格上最熱門文章的簡單任務的插件,創建的原因是因為找不到一個好的插件而感到沮喪。
此插件根據瀏覽量記錄了您最受歡迎的文章,並允許您使用自定義樣式在您的博客主題中顯示它們。您可以顯示過去一天、7天、30天或全部時間的熱門文章。
插件還附帶一個側邊欄小工具,讓您在博客側邊欄中顯示您的受歡迎的文章。
如果您是開發人員並將插件集成到主題中,則可以獲得更多靈活性,包括顯示最受歡迎的自定義文章類型等功能。
此插件由 WP Geeks 建立和維護。有關額外的文檔、視頻、片段和支持,請訪問 WP Most Popular 產品頁面。
用法
您可以以兩種方式使用此插件。
使用側邊欄小工具
在您的主題文件中使用定制函數
使用小工具是最簡單的方法,並且建議大多數用戶使用。如果您是開發人員並想將插件集成到現有主題中,請閱讀下面的信息。
首先,您需要在主題中包含用於檢索受歡迎文章的主要功能,稱為wp_most_popular_get_popular()。
您可以將該函數作為以下數組形式的參數傳遞:
limit(整數)
您想要顯示的文章數,例如 5
默認值:5
post_type(字符串)/(數組)
您想要顯示的文章類型
例如:post
默認值:所有文章類型
range(字符串)
您想顯示熱門文章的日期範圍
接受值:all_time、monthly、weekly、daily
默認值:all_time
這些是插件支持的當前參數。現在讓我們看一個示例,該示例顯示了最近的熱門文章,內容以無序列表形式顯示。
<?php
echo '<ul>';
$posts = wp_most_popular_get_popular( array( 'limit' => 10, 'post_type' => 'post', 'range' => 'all_time' ) );
global $post;
if ( count( $posts ) > 0 ): foreach ( $posts as $post ):
setup_postdata( $post );
?>
<li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a></li>
<?php
endforeach; endif;
echo '</ul>';
?>
過濾器
以下過濾器可供使用:
wp_most_popular_list_before - 用於過濾小工具列表中的 <ul> 元素
wp_most_popular_list_after - 用於過濾小工具列表中的 </ul> 元素
* wp_most_popular_list_item_single - 用於過濾小工具生成的列表項
操作
wp_most_popular_list_item - 用於修改列表輸出
外掛標籤
開發者團隊
原文外掛簡介
WP Most Popular was born out of frustration in finding a decent plugin which performs one simple task and that is to rank your most popular blog posts.
The plugin keeps a log of your most popular posts based on views and lets you display them in your blog theme with custom styling. You can display popular posts from the last day, 7 days, 30 days or all time.
It also comes with a sidebar widget to let you display your popular posts on your blogs sidebar.
If you are a developer and integrate the plugin in to a theme, you will get a lot more flexibility out of the plugin including the ability to show the most popular custom post types etc.
This plugin was built and is maintained by WP Geeks. For extra documentation, videos, snippets and support, visit the WP Most Popular product page.
Usage
There are two ways in which you can use this plugin.
As a sidebar widget
Custom function in your theme files
Using the widget is the easiest way and recommended for most users. If you are a developer and want to integrate the plugin in to your existing theme, then read the information below.
Firstly, the main function which you will need to include in your theme to fetch the popular posts is called wp_most_popular_get_popular().
You can pass that function the following parameters in array form:
limit (integer)
The number of posts you would like to display i.e. 5
Default: 5
post_type (string) / (array)
The post type you would like to display
Example: post
Default: All post types
range (string)
In what date range would you like to display popular posts in
Accepted: all_time, monthly, weekly, daily
Default: all_time
Those are the current parameters that the plugin supports. Let’s look at an example of how to display the most recent popular posts in a unordered list.
';
$posts = wp_most_popular_get_popular( array( 'limit' => 10, 'post_type' => 'post', 'range' => 'all_time' ) );
global $post;
if ( count( $posts ) > 0 ): foreach ( $posts as $post ):
setup_postdata( $post );
?>
';
?>
Filters
The following filters are available to you:
wp_most_popular_list_before – used to filter the
element of the outputted widget list
* **wp_most_popular_list_after** – used to filter the
element of the outputted widget list
* wp_most_popular_list_item_single – filters for a the list item generated by the widget
Actions
wp_most_popular_list_item – used for modifying the list output
