diff --git a/inc/core-rest.php b/inc/core-rest.php index f2a5f2d..9781894 100644 --- a/inc/core-rest.php +++ b/inc/core-rest.php @@ -25,6 +25,19 @@ function ajax_get_all_posts_callback() { $rows = tryGetValue( 'rows', 10 ); $page = tryGetValue( 'page', 1 ); + $sticky_ids = get_option('sticky_posts'); + $sticky_posts = []; //置顶文章 + if( ($type === 'all' || $type === 'post') && count($sticky_ids)>0 && $page <= 1 ){ + $args = array( + 'post__in' => $sticky_ids, + 'posts_per_page' => 4, + 'ignore_sticky_posts' => 1 + ); + $sticky_posts = query_posts($args); + }else{ + $sticky_posts = []; + } + // 查询条件 $args = [ 'post_type' => $type, @@ -35,6 +48,7 @@ function ajax_get_all_posts_callback() { 'order' => 'DESC', 'author' => get_current_user_id(), 'tax_query' => [], + 'post__not_in' => $sticky_ids, // 'has_password' => false, ]; @@ -89,6 +103,7 @@ function ajax_get_all_posts_callback() { } $posts = get_posts( $args ); // 文章 + $posts = array_merge($sticky_posts, $posts); $args['posts_per_page'] = - 1; $args['fields'] = 'ids'; @@ -144,7 +159,8 @@ function ajax_get_all_posts_callback() { } $post->thumbnail = replace_domain( $post->thumbnail ); - + $sticky_ids = get_option('sticky_posts'); + $post->is_sticky = is_array($sticky_ids) && in_array($post->id, $sticky_ids);//是否置顶 return $post; }, $posts ); diff --git a/static/lang.js b/static/lang.js index 0722682..c8f87b3 100644 --- a/static/lang.js +++ b/static/lang.js @@ -242,6 +242,11 @@ class Language { "zh_TC": "全部儲存", "ja": "全部を保存" }, + "Sticky": { + "zh_SC": "置顶", + "zh_TC": "置頂", + "ja": "上" + }, } } diff --git a/static/modules.js b/static/modules.js index a22592a..3874c15 100755 --- a/static/modules.js +++ b/static/modules.js @@ -21,7 +21,7 @@ const $modules = new function () {