From 7722f53f10fd6ce0a676586b5b22efe3b65b2035 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 4 May 2021 15:57:30 +0900 Subject: [PATCH] =?UTF-8?q?WP=20PLUGIN=20=E3=82=A2=E3=83=BC=E3=82=AB?= =?UTF-8?q?=E3=82=A4=E3=83=96=E6=AF=8E=E3=81=AB=E6=8A=95=E7=A8=BF=E8=A1=A8?= =?UTF-8?q?=E7=A4=BA=E9=A0=86=E3=82=92=E8=A8=AD=E5=AE=9A=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ・ファイル名、クラス名の変更 ・タクソノミーの有効化で、カテゴリー、タグ、カスタム分類のメタキーを分割 ・表示用クラスの追加 ・readmeの追加等 --- archive-post-oder-plus.php | 41 ++++++ .../class.apop.activate.php | 5 +- class/class.apop.order.php | 94 +++++++++++++ class/class.apop.ui.php | 73 ++++++++++ css/{base.css => apop-style.css} | 1 + js/{post-sort-cat-order.js => apop-style.js} | 0 lib/post-sort-cat-order.php | 125 ------------------ nb-post-sort-cat-order.php | 27 ---- readme.txt | 56 ++++++++ template/order.php | 53 ++++++++ template/setting.php | 111 +++++++++++++--- template/sort.php | 34 ----- 12 files changed, 409 insertions(+), 211 deletions(-) create mode 100644 archive-post-oder-plus.php rename lib/activate.php => class/class.apop.activate.php (91%) create mode 100644 class/class.apop.order.php create mode 100644 class/class.apop.ui.php rename css/{base.css => apop-style.css} (97%) rename js/{post-sort-cat-order.js => apop-style.js} (100%) delete mode 100644 lib/post-sort-cat-order.php delete mode 100644 nb-post-sort-cat-order.php create mode 100644 readme.txt create mode 100644 template/order.php delete mode 100644 template/sort.php diff --git a/archive-post-oder-plus.php b/archive-post-oder-plus.php new file mode 100644 index 0000000..2b306d1 --- /dev/null +++ b/archive-post-oder-plus.php @@ -0,0 +1,41 @@ + 'post', 'post_status' => array( 'publish', 'draft' ), 'posts_per_page' => - 1, 'category' => $cat_id, @@ -32,7 +31,7 @@ class activate { * @param $cat_id */ public static function create_sort_field( $post_id, $cat_id ) { - $sort_key = 'nb_post_sort_' . $cat_id; + $sort_key = '_apop_post_sort_' . $cat_id; //カスタムフィールドが存在しなければ追加する $sort_filed = get_post_meta( $post_id, $sort_key, true ); if ( empty( $sort_filed ) ) { diff --git a/class/class.apop.order.php b/class/class.apop.order.php new file mode 100644 index 0000000..65686aa --- /dev/null +++ b/class/class.apop.order.php @@ -0,0 +1,94 @@ +update_post_sort( 'category' ); + $this->update_post_sort( 'post_tag' ); + require_once self::TEMPLATE_DIR . 'success.php'; + } + + require_once self::TEMPLATE_DIR . 'order.php'; + } + + //投稿表示順の設定 + private function update_post_sort( $target ) { + $target = '_apop_post_' . $target; + $posts_sort = $_POST[ $target ]['post_sort']; + foreach ( $posts_sort as $cat_id => $posts ) { + $sort_key = $target . '_' . $cat_id; + foreach ( $posts as $post_id => $sort ) { + update_post_meta( $post_id, $sort_key, $sort ); + } + } + } + + + } +} + diff --git a/class/class.apop.ui.php b/class/class.apop.ui.php new file mode 100644 index 0000000..2949e84 --- /dev/null +++ b/class/class.apop.ui.php @@ -0,0 +1,73 @@ + $key, 'get' => 'all' ) ); + } + return get_taxonomies( array( 'public' => true, '_builtin' => false ) ); + } + + public static function get_tax_name( $tax_key ): string { + $tax_names = array( + 'category' => 'カテゴリー', + 'tag_id' => 'タグ', + 'custom_tax' => 'カスタム分類', + ); + + return $tax_names[ $tax_key ]; + } + + public static function get_cat_tag_list( $target, $key ): array { + $opt = get_option( '_apop_' . $target . '_order' ); + $include = array(); + if ( isset( $opt['target_cat'] ) ) { + foreach ( $opt['target_cat'] as $tax_id => $check ) { + if ( $check ) { + $include[] = $tax_id; + } + } + $include_tax = implode( ',', $include ); + if ( ! empty( $include_tax ) ) { + $args = array( + 'taxonomy' => $key, + 'hide_empty' => 0, + 'include' => $include_tax, + ); + + return get_terms( $args ); + } + } + + return array(); + } + + public static function get_sort_post_list( $tax_id, $search_param, $tax_key ) { + $args = [ + 'post_status' => array( 'publish', 'draft' ), + 'posts_per_page' => - 1, + $search_param => $tax_id, + 'orderby' => 'meta_value_num', + 'order' => 'ASC', + 'meta_key' => '_apop_post_' . $tax_key . '_' . $tax_id, + ]; + + return get_posts( $args ); + } + + public static function get_none_sort_post_list( $tax_id, $key, $exclude_posts ) { + $exclude = implode( ',', $exclude_posts ); + $args = [ + 'post_status' => array( 'publish', 'draft' ), + 'posts_per_page' => - 1, + $key => $tax_id, + ]; + if ( ! empty( $exclude ) ) { + $args['exclude'] = $exclude; + } + + return get_posts( $args ); + } + +} \ No newline at end of file diff --git a/css/base.css b/css/apop-style.css similarity index 97% rename from css/base.css rename to css/apop-style.css index 21fe4c9..e6ce059 100644 --- a/css/base.css +++ b/css/apop-style.css @@ -40,6 +40,7 @@ h3 { .list-orders-outer { width: 100%; + margin-bottom: 1em; display: flex; justify-content: flex-start; flex-wrap: wrap; diff --git a/js/post-sort-cat-order.js b/js/apop-style.js similarity index 100% rename from js/post-sort-cat-order.js rename to js/apop-style.js diff --git a/lib/post-sort-cat-order.php b/lib/post-sort-cat-order.php deleted file mode 100644 index 5a35825..0000000 --- a/lib/post-sort-cat-order.php +++ /dev/null @@ -1,125 +0,0 @@ -update_post_sort(); - require_once self::TEMPLATE_DIR . 'success.php'; - } - - require_once self::TEMPLATE_DIR . 'sort.php'; - } - - //投稿表示順の設定 - private function update_post_sort() { - $posts_sort = $_POST['nb_post_cat']['post_sort']; - foreach ( $posts_sort as $cat_id => $posts ) { - $sort_key = 'nb_post_sort_' . $cat_id; - foreach ( $posts as $post_id => $sort ) { - update_post_meta( $post_id, $sort_key, $sort ); - } - } - } - - - /** - * 対象カテゴリー - * - * @param $opt - * - * @return array - */ - public static function get_category_list( $opt ): array { - if ( isset( $opt['target_cat'] ) ) { - $include_cat = implode( ',', $opt['target_cat'] ); - if ( ! empty( $include_cat ) ) { - $category_args = array( - 'hide_empty' => 0, - 'include' => $include_cat, - ); - - return get_categories( $category_args ); - } - } - - return array(); - } - - -// public function add_cat_post_order( $new_status, $old_status, $post ) { -// //リビジョンはパスする -// if ( wp_is_post_revision( $post->ID ) ) { -// return; -// } -// -// } - - public static function get_sort_post_list( $cat_id ) { - $product_args = [ - 'post_type' => 'post', - 'post_status' => array( 'publish', 'draft' ), - 'posts_per_page' => - 1, - 'category' => $cat_id, - 'orderby' => 'meta_value_num', - 'order' => 'ASC', - 'meta_key' => 'nb_post_sort_' . $cat_id, - ]; - - return get_posts( $product_args ); - } - - } -} - diff --git a/nb-post-sort-cat-order.php b/nb-post-sort-cat-order.php deleted file mode 100644 index b0dbb95..0000000 --- a/nb-post-sort-cat-order.php +++ /dev/null @@ -1,27 +0,0 @@ - + + + +== Installation == + += 自動インストール = +1. プラグインの検索フィールドより「Archive Post Order Plus」や「投稿表示順」と入力し、"プラグインの検索"をクリックします。 +1. 当プラグインを見つけたら、"今すぐインストール"をクリックしてインストールし、プラグインを有効化してください。 + += 手動インストール = +1. プラグインをダウンロードします。 +1. プラグインフォルダ内にアップロードし、管理画面よりプラグインを有効化してください。 + + +== Frequently Asked Questions == + +== Screenshots == + +1. /assets/screenshot-1.png +2. /assets/screenshot-2.png +3. /assets/screenshot-3.png +4. /assets/screenshot-4.png +5. /assets/screenshot-5.png +6. /assets/screenshot-6.png + +== Changelog == + += 1.0.0 = +Initial working version. + +== Upgrade Notice == +No information diff --git a/template/order.php b/template/order.php new file mode 100644 index 0000000..f1978ad --- /dev/null +++ b/template/order.php @@ -0,0 +1,53 @@ + APOP_UI::get_cat_tag_list( 'cat', 'category' ), + 'tag_id' => APOP_UI::get_cat_tag_list( 'tag', 'post_tag' ), +); +?> +
+
+ + $tax_list ) : ?> +
+ +

対象を選択してください。 + [ 選択 ] +

+ + +
+

name; ?>

+ term_id, $tax_key, $tax_data->taxonomy ); ?> +
    + $target_post ): $sort_num = $key + 1; + $exclude_posts[] = $target_post->ID; ?> +
  • + + ID ); ?> + +
  • + + term_id, $tax_key, $exclude_posts ); ?> + 0 ): ?> + + $target_post_no_order ): $sort_num_no_order = $sort_num + $key + 1; ?> +
  • + + ID ); ?> + +
  • + + +
+
+ + +
+ +

+
+
\ No newline at end of file diff --git a/template/setting.php b/template/setting.php index 36a8775..243c766 100644 --- a/template/setting.php +++ b/template/setting.php @@ -1,33 +1,100 @@
-

対象カテゴリー選択

-
    - -
  • -
    - -
    -
  • - -
+

対象タクソノミー選択

+ + 0 ): ?> + + + + + + 0 ): ?> + + + + + + 0 ): ?> + + + + + +
カテゴリー +
    + + term_id ] ?? ''; ?> +
  • +
    + +
    +
  • + +
+
タグ +
    + + term_id ] ?? ''; ?> +
  • +
    + +
    +
  • + +
+
カスタム分類 +
    + + + term_id ] ?? ''; ?> +
  • +
    + +
    +
  • + + +
+

\ No newline at end of file diff --git a/template/sort.php b/template/sort.php deleted file mode 100644 index a0ff51a..0000000 --- a/template/sort.php +++ /dev/null @@ -1,34 +0,0 @@ - -
-
- -

投稿表示順設定

-
- -

対象カテゴリーを選択してください。[ カテゴリー選択

- - -
-

name; ?>

- term_id ); ?> -
    - $target_post ): $sort_num = $key + 1; ?> -
  • - - ID ); ?> - -
  • - -
-
- - -
-

-
-
\ No newline at end of file