From b2663eca8a32c6f2cab5d09d702ca10264cf6353 Mon Sep 17 00:00:00 2001 From: moxiaonai <52moxiaonai@gmail.com> Date: Sun, 26 Feb 2023 22:36:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=BA=86=E9=A6=96?= =?UTF-8?q?=E9=A1=B5=E6=96=87=E7=AB=A0=E5=88=97=E8=A1=A8=E7=BD=AE=E9=A1=B6?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/core-rest.php | 18 +++++++++++++++++- static/lang.js | 5 +++++ static/modules.js | 15 ++++++++------- style.css | 12 ++++++++++++ 4 files changed, 42 insertions(+), 8 deletions(-) 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 () {
{{ author.display_name }}
{{ author.description }} - +
- + - + - +