From df9c7deef11b395913b07e4cf29bcb3374dde086 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 8 May 2021 11:50:31 +0900 Subject: [PATCH] =?UTF-8?q?WP=20PLUGIN=20=E6=8A=95=E7=A8=BF=E8=A1=A8?= =?UTF-8?q?=E7=A4=BA=E9=A0=86=E8=A8=AD=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ・タクソノミーのソート順登録/未登録両方取得するようget_postsのパラメータを修正 ・タクソノミーのソート順登録/未登録両方取得に伴いテンプレートを修正 ・通常と検索のソート順登録/未登録両方取得するようget_postsのパラメータを修正 ・「表示設定に従う」メニューへposts_per_pageの設定件数を表示 ・バグ修正:検索設定のnema属性修正と検索ページのメソッド引数修正 --- class/class.apop.ui.php | 178 +++++++++--------- css/apop-style.css | 64 +++++-- js/apop-style.js | 2 - template/order.php | 348 +++++++++++++++--------------------- template/setting.php | 23 ++- template/success.php | 4 +- util/apop-order-setting.php | 41 +++-- 7 files changed, 334 insertions(+), 326 deletions(-) diff --git a/class/class.apop.ui.php b/class/class.apop.ui.php index 264b91b..48c8b26 100644 --- a/class/class.apop.ui.php +++ b/class/class.apop.ui.php @@ -15,24 +15,47 @@ if ( ! class_exists( 'APOP_UI' ) ) { return $type_data; } - public static function get_all_search_normal_posts( $type, $key, $exclude_posts = [] ) { - $args = [ - 'post_status' => array( 'publish', 'draft' ), - 'posts_per_page' => - 1, - ]; - - if ( $type == 'registered' ) { - $args['orderby'] = 'meta_value_num'; - $args['order'] = 'ASC'; - $args['meta_key'] = '_apop_post_' . $key; - } else { - $exclude = implode( ',', $exclude_posts ); - if ( ! empty( $exclude ) ) { - $args['exclude'] = $exclude; - } + public static function get_all_search_normal_posts( $key ): string { + $meta_key = '_apop_post_' . $key; + $args = self::create_search_normal_args( $meta_key ); + $posts_data = get_posts( $args ); + $list = []; + foreach ( $posts_data as $i => $post_data ) { + $order = $i + 1; + $no_order = self::is_sort_post_registered( $post_data->ID, $meta_key ) ? '' : ' no_order'; + $list[] = '
  • ' . self::crate_non_registerd_mark( $no_order ) . ' +' . $order . '' . $post_data->post_title . ' + +
  • '; } - return get_posts( $args ); + return implode( PHP_EOL, $list ); + } + + private static function crate_non_registerd_mark( $no_order ) { + if ( ! empty( $no_order ) ) { + return '■'; + } + + return ''; + } + + private static function create_search_normal_args( $meta_key ): array { + return array( + 'post_status' => array( 'publish', 'draft' ), + 'posts_per_page' => - 1, + 'meta_query' => array( + 'relation' => 'OR', + array( + 'key' => $meta_key, + 'compare' => 'EXISTS', + ), + array( + 'key' => $meta_key, + 'compare' => 'NOT EXISTS', + ), + ), + ); } @@ -98,45 +121,64 @@ if ( ! class_exists( 'APOP_UI' ) ) { return array(); } - public static function create_order_list( $tax_data, $tax_key, $exclude_posts ): array { - $target_posts = self::get_sort_post_list( $tax_data->term_id, $tax_key, $tax_data->taxonomy ); - $list = []; - $sort_num = 0; - foreach ( $target_posts as $key => $target_post ) { - $sort_num = $key + 1; - $exclude_posts[] = $target_post->ID; - $list[] = ' -
  • ' . $sort_num . '' . get_the_title( $target_post->ID ) . ' + public static function create_order_list( $tax_data, $tax_key ): string { + $return_data = self::get_sort_post_list( $tax_data->term_id, $tax_key, $tax_data->taxonomy ); + $list = []; + foreach ( $return_data['data'] as $key => $target_post ) { + $sort_num = $key + 1; + $no_order = self::is_sort_post_registered( $target_post->ID, $return_data['meta_key'] ) ? '' : ' no_order'; + $list[] = ' +
  • ' . self::crate_non_registerd_mark( $no_order ) . '' . $sort_num . '' . get_the_title( $target_post->ID ) . '
  • '; } - return array( - implode( PHP_EOL, $list ), - $exclude_posts, - $sort_num, - ); - + return implode( PHP_EOL, $list ); } - private static function get_sort_post_list( $tax_id, $search_param, $tax_name ) { - $args = [ + private static function is_sort_post_registered( $id, $key ): bool { + if ( get_post_meta( $id, $key, true ) ) { + return true; + } + + return false; + } + + private static function get_sort_post_list( $tax_id, $search_param, $tax_name ): array { + $args = array( 'post_status' => array( 'publish', 'draft' ), 'posts_per_page' => - 1, 'orderby' => 'meta_value_num', 'order' => 'ASC', - 'meta_key' => '_apop_post_' . self::create_post_sort_key( $tax_name, $search_param ) . '_' . $tax_id, - ]; - - + ); + $meta_key = '_apop_post_' . self::create_post_sort_key( $tax_name, $search_param ) . '_' . $tax_id; + self::create_sort_post_list_meta_query( $args, $meta_key ); self::create_post_tax_query( $args, $search_param, $tax_name, $tax_id ); - return get_posts( $args ); + return array( + 'meta_key' => $meta_key, + 'data' => get_posts( $args ) + ); } - private static function create_post_sort_key( $tax_name, $tax_key ) { + private static function create_sort_post_list_meta_query( &$args, $meta_key ) { + + $args['meta_query'] = array( + 'relation' => 'OR', + array( + 'key' => $meta_key, + 'compare' => 'EXISTS', + ), + array( + 'key' => $meta_key, + 'compare' => 'NOT EXISTS', + ), + ); + } + + public static function create_post_sort_key( $tax_name, $tax_key ) { if ( $tax_key == 'taxonomy' ) { return 'tax'; } @@ -159,45 +201,6 @@ value="' . $sort_num . '"> } } - public static function create_product_none_order_list( $tax_data, $tax_key, $exclude_posts, $sort_num ): string { - $target_posts_no_order = self::get_none_sort_post_list( $tax_data->term_id, $tax_key, $exclude_posts, $tax_data->taxonomy ); - if ( count( $target_posts_no_order ) > 0 ) { - $sort_num = $sort_num ?? 0; - foreach ( $target_posts_no_order as $key => $target_post_no_order ) { - $sort_num_no_order = $sort_num + $key + 1; - $list[] = ' -
  • ■ -' . $sort_num_no_order . '' . get_the_title( $target_post_no_order->ID ) . ' - -
  • '; - } - if ( isset( $list ) ) { - return implode( PHP_EOL, $list ); - } - } - - return ''; - } - - private static function get_none_sort_post_list( $tax_id, $search_param, $exclude_posts, $tax_name ) { - - $args = array( - 'post_status' => array( 'publish', 'draft' ), - 'posts_per_page' => - 1, - ); - - $exclude = implode( ',', $exclude_posts ); - if ( ! empty( $exclude ) ) { - $args['exclude'] = $exclude; - } - - self::create_post_tax_query( $args, $search_param, $tax_name, $tax_id ); - - return get_posts( $args ); - } - public static function create_cat_per_page( $opt_per_page, $type ): array { $cat_per_page = $opt_per_page[ $type ] ?? 'default'; $checked = ''; @@ -235,19 +238,20 @@ value="' . $sort_num_no_order . '"> $alert = ! $order_param[ $target_key ]['use'] ? '

    並べ替えを登録するには「変更を保存」をクリックしてください。

    ' : ''; $no_order_class = ! $order_param[ $target_key ]['use'] ? ' no_order' : ''; $list[] = '
  • +
    ' . $target_values[ $target_key ] . '
    +
    -    -    + +
  • '; } @@ -293,18 +297,20 @@ value="' . $sort_num_no_order . '"> } } - public static function create_disp_class( $disp ) { + public static function create_disp_class( $disp ): string { if ( ! $disp ) { return ' class="hide_list"'; } + + return ''; } - public static function create_none_select_msg( $str ) { + public static function create_none_select_msg( $str ): string { return '

    並べ替えをカスタマイズする' . $str . 'は選択されていません。

    '; } - public static function none_registerd_alert_msg() { - return '
    ■の項目は未登録項目です。ドラッグして並び順を変更後に「変更を保存」をクリックしてください。
    '; + public static function none_registered_alert_msg(): string { + return '
    ■は未登録項目です。ドラッグして並び順を変更後に「変更を保存」をクリックしてください。
    '; } } diff --git a/css/apop-style.css b/css/apop-style.css index 0c83ac0..c60f8e5 100644 --- a/css/apop-style.css +++ b/css/apop-style.css @@ -1,5 +1,10 @@ @charset "UTF-8"; +h3 { + font-weight: normal; + font-size: 16px; +} + .post-order-nav { width: 95%; } @@ -30,8 +35,12 @@ margin-right: 0; } +.post-setting-box { + margin: 5px 15px; +} + .post-order-box-outer { - width: 95%; + width: 100%; margin: -1px 0 2em; border-top: 1px solid #999; } @@ -40,11 +49,6 @@ display: none; } -h3 { - font-weight: normal; - font-size: 16px; -} - .list-orders-outer { width: 100%; margin-bottom: 1em; @@ -54,7 +58,7 @@ h3 { } .list-orders-inner { - width: calc((100% - 10px) / 5); + width: calc((100% - 10px) / 2); margin: 1.5em 1em 0 0; padding: .5em; border: 1px solid #999; @@ -107,8 +111,7 @@ dl.apop_setting_list dd:first-of-type { } .product-list { - padding: .5em; - border-radius: 4px; + padding: 1em .5em; background: #fff; cursor: move; color: #4b4b4b; @@ -116,12 +119,22 @@ dl.apop_setting_list dd:first-of-type { } .search_normal_sort .product-list { - padding: 1em .5em; - border-radius: 0px; + display: flex; } -.search_normal_sort .product-list label:first-of-type { - width: 100px; +.search_normal_sort .product-list-type-label { + width: calc(100% / 2); + display: flex; + justify-content: space-between; +} + +.search_normal_sort .product-list-sort-type { + width: 100%; + display: flex; +} + +.search_normal_sort .product-list-sort-type label { + width: calc((100% / 4) - 5px); } .product-list.no_order { @@ -145,9 +158,30 @@ dl.apop_setting_list dd:first-of-type { } .no_registered_exp { + width: 100%; margin-top: 1em; } +@media only screen and (max-width: 1264px) { + .search_normal_sort .product-list { + display: block; + } + + .search_normal_sort .product-list-type-label { + width: 100%; + margin-bottom: 1em; + display: block; + } + + .search_normal_sort .product-list-sort-type { + width: 100%; + } + + .search_normal_sort .product-list-sort-type label { + width: calc((100% / 3) - 5px); + } +} + @media only screen and (max-width: 964px) { .post-order-nav { @@ -159,11 +193,11 @@ dl.apop_setting_list dd:first-of-type { } .list-orders-inner.search_inner { - width: 100%; + width: auto; } .list-orders-inner { - width: 100%; + width: auto; margin: 1.5em 0 0 0; } diff --git a/js/apop-style.js b/js/apop-style.js index bd2e40e..f97ade7 100644 --- a/js/apop-style.js +++ b/js/apop-style.js @@ -10,8 +10,6 @@ jQuery(function ($) { change_search_order(); change_normal_order(); - en_search_normal_sort_btn() - //per page disp_tax_per_page(); change_normal_per_page(); diff --git a/template/order.php b/template/order.php index db1e578..3537a6c 100644 --- a/template/order.php +++ b/template/order.php @@ -1,6 +1,6 @@ APOP_UI::get_cat_tag_list( 'cat', 'category' ) ); $tag_lists = array( 'tag_id' => APOP_UI::get_cat_tag_list( 'tag', 'post_tag' ) ); $taxonomy_lists = array( 'taxonomy' => APOP_UI::get_cat_tag_list( 'tax', 'taxonomy' ) ); @@ -8,230 +8,176 @@ $submit_type = APOP_UI::input_post_filter( 'submit_type', 'str' ); $apop_search_order_check = APOP_UI::get_order_type( '_apop_search_order' ); $apop_normal_check = APOP_UI::get_order_type( '_apop_normal_order' ); ?> -

    並べ替え

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

      並べ替え

      + +
      +
      +
      + +
      + + +
        +
      • +
      -
      +
      +
      + + +
        + +
      +
      -
      - -
        - $normal_list ): $normal_order = $i + 1; ?> - ID; ?> -
      • - - post_title; ?> - -
      • - - - - $search_list ): $normal_order = $normal_order + $i + 1; ?> -
      • ■ - - post_title; ?> - -
      • - -
      -
      +
      + +
        + +
      +
      - -

      + +

      - + +
      -
      -
      -
      - -
      -
      - -
        -
      • -
      • -
      -
      -
      - - -
        - +
        +
        + +
        + + +
          +
        • +
        -
        +
        +
        + + +
          + +
        +
        -
        - -
          - $search_list ): $search_order = $i + 1; ?> - ID; ?> -
        • - - post_title; ?> - -
        • - - - - $search_list ): $search_order = $search_order + $i + 1; ?> -
        • ■ - - post_title; ?> - -
        • - -
        -
        +
        + +
          + +
        +
        - -

        + +

        - + +
      -
      -
      - 0 ): ?> - - - $tax_list ) : ?> -
      - 0 ): $exclude_posts = []; ?> - -
      -
      - -

      name; ?>

      -
        - -
      - -

      -
      -
      - - - - -
      - -
      -
      - 0 ): ?> - - - $tax_list ) : ?> -
      - 0 ): $exclude_posts = []; ?> - -
      -
      - -

      name; ?>

      -
        - -
      - -

      -
      -
      - - - - -
      - -
      -
      - 0 ): ?> - - - $taxonomy_list ): ?> -
      - - 0 ): $exclude_posts = []; ?> +
      + $tax_list ) : ?> +
      + 0 ): ?> +

      name; ?>

        - +
      - +

      + + - - - - -
      - +
      + +
      +
      + $tax_list ) : ?> +
      + 0 ): ?> + + +
      +
      + +

      name; ?>

      +
        + +
      + +

      +
      +
      + + + + +
      + +
      +
      + $taxonomy_list ): ?> +
      + + 0 ): ?> + + +
      +
      + +

      name; ?>

      +
        + +
      + +

      +
      +
      + + + + + + +
      + +
      \ No newline at end of file diff --git a/template/setting.php b/template/setting.php index f08ccfe..e80415d 100644 --- a/template/setting.php +++ b/template/setting.php @@ -8,10 +8,11 @@ $all_tax = APOP_UI::get_all_taxonomies( 'taxonomy' );

      設定

      @@ -25,7 +26,8 @@ $all_tax = APOP_UI::get_all_taxonomies( 'taxonomy' );
    • + value="default">表示設定に従う( + 件)
    • カテゴリー設定 @@ -82,7 +84,8 @@ $all_tax = APOP_UI::get_all_taxonomies( 'taxonomy' );
    • + value="default">表示設定に従う( + 件)