
內容簡介
Featured Posts Pro
讓管理員和編輯能夠輕易地將文章、頁面和自訂文章設定為特色文章。您可以在文章列表頁面或文章編輯頁面上透過勾選方塊,將文章、頁面和自訂文章設為特色文章。請參閱截圖以了解更多。
Featured Posts Pro 也新增了一個小工具,用於列出最近的特色文章。這與預設的最新文章小工具類似,但這個小工具會顯示最近的特色文章。Featured Posts Pro 小工具的樣板可以透過您的佈景主題進行自訂。
如何在佈景主題中使用
要取得特色文章,您需要建立自訂查詢,如下所示:
取得帶有排列順序的特色文章範例程式碼
$args = array(
‘post_type’ => ‘any’,
‘posts_per_page’ => 10,
‘no_found_rows’ => true,
‘post_status’ => ‘publish’,
‘ignore_sticky_posts’ => true,
‘meta_query’ => array(
array(
‘relation’ => ‘OR’,
array(
‘key’ => ‘post_featured_position’,
‘compare’ => ‘EXISTS’
),
array(
‘key’ => ‘post_featured_position’,
‘compare’ => ‘NOT EXISTS’
),
),
array(
‘relation’ => ‘AND’,
‘key’ => ‘is_post_featured’,
‘compare’ => ‘=’,
‘value’ => 1
)
),
‘orderby’ => ‘meta_value_num’,
‘order’ => ‘ASC’,
) ;
$featuredPosts = new WP_Query( $args );
<h3>取得沒有排序的特色文章範例程式碼</h3>$args = array(
‘posts_per_page’ => 10,
‘no_found_rows’ => true,
‘post_status’ => ‘publish’,
‘ignore_sticky_posts’ => true,
‘meta_key’ => ‘is_post_featured’ // 這是用於特色文章的元鍵
) ;
$featuredPosts = new WP_Query( $args );
或者如果您只想
如何自訂小工具
您可以按照以下步驟自訂小工具樣板:
1. 在您的佈景主題資料夾中建立名為 ‘featured_posts_pro_tpls’ 的資料夾
2. 在剛才建立的 ‘featured_posts_pro_tpls’ 資料夾中建立兩個名為 ‘tpl_featured_posts_pro_large.php’ 和 ‘tpl_featured_posts_pro_small.php’ 的 PHP 檔案
3. 當小工具大小設定為大時,樣板檔案 ‘tpl_featured_posts_pro_large.php’ 將用於呈現小工具,同理,‘tpl_featured_posts_pro_small.php’ 則用於小型小工具
4. 從插件資料夾 > featured-posts-pro > public > partials > featured_posts_pro-widget.php 中複製並貼上內容到上述兩個檔案中
外掛標籤
開發者團隊
原文外掛簡介
Featured Posts Pro
allows administrator and editor an option to set posts, pages & custom posts as a featured posts very easily. Posts, pages & custom posts can be set as featured posts using a checkbox on the posts list page or on the edit page of the post. Please see screenshots to be more clear.
Featured Posts Pro
also adds a widget that will list the recent featured posts. This is similar to the default recent posts widget except this widget displays recent featured posts instead. The template for the Featured Posts Pro Widget can be customized with your theme.
How to use in the theme
You can to get the featured posts, you need to make a custom query as follows
sample code to get the featured posts with orders
`$args = array(
‘post_type’ => ‘any’,
‘posts_per_page’ => 10,
‘no_found_rows’ => true,
‘post_status’ => ‘publish’,
‘ignore_sticky_posts’ => true,
‘meta_query’ => array(
array(
‘relation’ => ‘OR’,
array(
‘key’ => ‘post_featured_position’,
‘compare’ => ‘EXISTS’
),
array(
‘key’ => ‘post_featured_position’,
‘compare’ => ‘NOT EXISTS’
),
),
array(
‘relation’ => ‘AND’,
‘key’ => ‘is_post_featured’,
‘compare’ => ‘=’,
‘value’ => 1
)
),
‘orderby’ => ‘meta_value_num’,
‘order’ => ‘ASC’,
) ;
$featuredPosts = new WP_Query( $args );
sample code to get the featured posts without order
$args = array(
‘posts_per_page’ => 10,
‘no_found_rows’ => true,
‘post_status’ => ‘publish’,
‘ignore_sticky_posts’ => true,
‘meta_key’ => ‘is_post_featured’ //this is the meta key used for the featured posts
) ;
$featuredPosts = new WP_Query( $args );`
or if you simple want tp
How to customize the widget
You can customize the widget template as follows:
1. create a folder ‘featured_posts_pro_tpls’ inside your theme folder
2. create two php files named as ‘tpl_featured_posts_pro_large.php’ & ‘tpl_featured_posts_pro_small.php’ in the ‘featured_posts_pro_tpls’ folder you just created
3. template file ‘tpl_featured_posts_pro_large.php’ will be used to render the widget when widget size is selected as large & similarly ‘tpl_featured_posts_pro_small.php’ is for small widget size
3. copy and paste the content from plugin_fold er > featured-posts-pro > public > partials > featured_posts_pro-widget.php in the above two files
4. make the layout changes as you wish.
