diff --git a/class/class.apop.order.php b/class/class.apop.order.php index 563a459..3c90193 100644 --- a/class/class.apop.order.php +++ b/class/class.apop.order.php @@ -125,10 +125,26 @@ if ( ! class_exists( 'APOP' ) ) { //------------------------------------- // タクソノミー // ------------------------------------ + $tax_sort_type = APOP_UI::input_post_filter( '_apop_tax_sort_type', 'array' ); + $apop_tax_order_param = APOP_UI::input_post_filter( '_apop_tax_order_param', 'array' ); $apop_post_category = APOP_UI::input_post_filter( '_apop_post_category', 'array' ); $apop_post_post_tag = APOP_UI::input_post_filter( '_apop_post_post_tag', 'array' ); $apop_post_tax = APOP_UI::input_post_filter( '_apop_post_tax', 'array' ); + //カテゴリーのソートタイプ設定 + if ( $tax_sort_type ) { + check_admin_referer( 'sh_options' ); + update_option( '_apop_tax_sort_type', $tax_sort_type ); + require_once self::TEMPLATE_DIR . 'success.php'; + } + + //カテゴリーの標準ソートパラメータ + if ( $apop_tax_order_param ) { + check_admin_referer( 'sh_options' ); + update_option( '_apop_tax_order_param', $apop_tax_order_param ); + require_once self::TEMPLATE_DIR . 'success.php'; + } + //カテゴリーの投稿表示順設定 if ( $apop_post_category ) { check_admin_referer( 'sh_options' ); diff --git a/class/class.apop.ui.php b/class/class.apop.ui.php index 3201500..ee78e24 100644 --- a/class/class.apop.ui.php +++ b/class/class.apop.ui.php @@ -15,7 +15,9 @@ if ( ! class_exists( 'APOP_UI' ) ) { return $type_data; } - public static function get_all_search_normal_posts( $key ): string { + 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 ); @@ -95,17 +97,20 @@ if ( ! class_exists( 'APOP_UI' ) ) { foreach ( $opt['target_cat'] as $tax_id => $status ) { //フラグが立っているカスタムタクソノミーは情報を取得する if ( $status ) { - $args = array( + $args = array( 'taxonomy' => get_term( $tax_id )->taxonomy, 'hide_empty' => 0, 'include' => $tax_id, ); - $tax_data[] = get_terms( $args ); + $tax_data = array_merge( $tax_data, get_terms( $args ) ); } } + if ( count( $tax_data ) > 0 ) { + return $tax_data; + } - return $tax_data; + return array(); } private static function create_tax_term( $opt, $key ) { @@ -261,46 +266,125 @@ value="' . $sort_num . '"> ); } - public static function create_search_normal_list( $type ): array { - $name_key = 'apop_' . $type . '_order_param'; - $order_param = get_option( '_' . $name_key ); + public static function create_search_normal_list( $type, $id = null ): array { + $name_keys = self::create_name_keys( $id, $type ); + $name_key = $name_keys['name_key']; + $get_option_key = $name_keys['get_option_key']; + $order_param_base = get_option( $get_option_key ); + $order_param = ''; + if ( is_null( $id ) ) { + $order_param = $order_param_base; + } + if ( isset( $order_param_base[ $id ] ) ) { + $order_param = $order_param_base[ $id ]; + } $target_keys = self::set_search_normal_target_keys( $order_param ); $target_values = array( - 'date' => '登録日', - 'title' => 'タイトル', - 'ID' => 'ID', - 'modified' => '更新日', + 'date' => '登録日', + 'title' => 'タイトル', + 'ID' => 'ID', + 'modified' => '更新日', + 'custom_field' => 'カスタムフィールド', ); $list = array(); foreach ( $target_keys as $target_key ) { - $use = $order_param[ $target_key ]['use'] ?? 0; - $sort = $order_param[ $target_key ]['sort'] ?? 2; - $alert = ! $order_param[ $target_key ]['use'] ? '

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

' : ''; - $no_order_class = ! $order_param[ $target_key ]['use'] ? ' no_order' : ''; - $list[] = '
  • + $cnv_order_params = self::set_order_list_param( $order_param, $target_key ); + $use = $cnv_order_params['use']; + $sort = $cnv_order_params['sort']; + $alert = $cnv_order_params['alert']; + $no_order_class = $cnv_order_params['no_order_class']; + if ( $target_key == 'custom_field' ) { + $meta_key = $cnv_order_params['custom_field']['meta_key']; + $value_type = $cnv_order_params['custom_field']['value_type']; + $field_metakey_input = self::create_custom_field_sort_type( $name_key, $target_key, $meta_key, $value_type ); + } + $list[] = '
  • ' . $target_values[ $target_key ] . '
    - - - -
    +
  • '; } return array( implode( PHP_EOL, $list ), $alert, + $field_metakey_input, ); } + private static function create_custom_field_sort_type( $name_key, $target_key, $meta_key, $value_type ): string { + return '
    カスタムフィールドキー: + +値タイプ: + + +
    '; + } + + private static function set_order_list_param( $order_param, $target_key ): array { + + $param = array( + 'use' => 0, + 'sort' => 2, + 'alert' => '

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

    ', + 'no_order_class' => ' no_order', + ); + if ( $target_key == 'custom_field' ) { + $param['custom_field'] = array( + 'meta_key' => '', + 'value_type' => 'meta_value', + ); + } + + if ( isset( $order_param[ $target_key ] ) ) { + $param = array( + 'use' => $order_param[ $target_key ]['use'] ?? 0, + 'sort' => $order_param[ $target_key ]['sort'] ?? 2, + 'alert' => ! $order_param[ $target_key ]['use'] ? '

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

    ' : '', + 'no_order_class' => ! $order_param[ $target_key ]['use'] ? ' no_order' : '', + ); + if ( $target_key == 'custom_field' ) { + $param['custom_field'] = array( + 'meta_key' => $order_param[ $target_key ]['field']['meta_key'] ?? '', + 'value_type' => $order_param[ $target_key ]['field']['value_type'] ?? 'meta_value', + ); + } + } + + return $param; + + } + + private static function create_name_keys( $id, $type ): array { + if ( is_null( $id ) ) { + return array( + 'name_key' => 'apop_' . $type . '_order_param', + 'get_option_key' => '_' . 'apop_' . $type . '_order_param', + ); + } else { + return array( + 'name_key' => 'apop_tax_order_param[' . $id . ']', + 'get_option_key' => '_apop_tax_order_param', + ); + } + } + private static function set_search_normal_target_keys( $post_apop_search_order_param ) { if ( $post_apop_search_order_param ) { return array_keys( $post_apop_search_order_param ); @@ -311,6 +395,7 @@ value="' . $sort_num . '"> 'title', 'ID', 'modified', + 'custom_field' ); } @@ -337,14 +422,6 @@ value="' . $sort_num . '"> } } - public static function create_disp_class( $disp ): string { - if ( ! $disp ) { - return ' class="hide_list"'; - } - - return ''; - } - public static function create_none_select_msg( $str ): string { return '

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

    '; } diff --git a/css/apop-style.css b/css/apop-style.css index 8e6650c..a81a046 100644 --- a/css/apop-style.css +++ b/css/apop-style.css @@ -52,30 +52,21 @@ h3 { .list-orders-outer { width: 100%; margin-bottom: 1em; - display: flex; - justify-content: flex-start; - flex-wrap: wrap; } .list-orders-inner { - width: 45%;; + width: 50%; margin: 1.5em 1em 0 0; padding: .5em; border: 1px solid #999; position: relative; } -.list-orders-inner.search_inner { - width: 50%; -} - -.apop_normal_order_target, -.apop_search_order_target { +.sort_menu_list { display: flex; } -.apop_normal_order_target li:first-child, -.apop_search_order_target li:first-child { +.sort_menu_list li:first-child { margin-right: 2em; } @@ -123,8 +114,6 @@ dl.apop_setting_list dd:first-of-type { .search_normal_sort .product-list-type-label { width: calc(100% / 2); - display: flex; - justify-content: space-between; } .search_normal_sort .product-list-sort-type { @@ -152,9 +141,9 @@ dl.apop_setting_list dd:first-of-type { content: "]"; } -.hide_list { - display: none; -} +/*.hide_list {*/ +/* display: none;*/ +/*}*/ .no_registered_exp { width: 100%; @@ -172,6 +161,10 @@ dl.apop_setting_list dd:first-of-type { border-top: 1px solid #ccc; } +.sort_custom_field{ + width: 100%; +} + @media only screen and (max-width: 1264px) { .search_normal_sort .product-list { display: block; @@ -202,10 +195,6 @@ dl.apop_setting_list dd:first-of-type { display: block;; } - .list-orders-inner.search_inner { - width: auto; - } - .list-orders-inner { width: auto; margin: 1.5em 0 0 0; diff --git a/js/apop-style.js b/js/apop-style.js index c85a73d..32fc553 100644 --- a/js/apop-style.js +++ b/js/apop-style.js @@ -7,8 +7,9 @@ jQuery(function ($) { order_list(); //order type - change_search_order(); - change_normal_order(); + // change_search_order(); + // change_normal_order(); + change_sort_box(); //Tax select select_tax(); @@ -28,7 +29,7 @@ jQuery(function ($) { $('.post-order-nav li:eq(' + submit_type + ')').addClass('en'); $('.post-order-box:eq(' + submit_type + ')').show() - order_nav_list.click(function () { + order_nav_list.on('click', function () { if (!$(this).hasClass('en')) { let target_index = $(this).index(); order_nav_list.removeClass('en'); @@ -69,7 +70,7 @@ jQuery(function ($) { }); $('.normal_sort_box:eq(' + default_index + ')').show().find('input').prop('disabled', false); - s_radio.click(function () { + s_radio.on('click', function () { let target_index = $(this).val() - 1; s_box.hide().find('input').each(function () { $(this).prop('disabled', true); @@ -89,7 +90,7 @@ jQuery(function ($) { $('.search_sort_box:eq(' + default_index + ')').show().find('input').prop('disabled', false); - s_radio.click(function () { + s_radio.on('click', function () { let target_index = $(this).val() - 1; s_box.hide().find('input').each(function () { $(this).prop('disabled', true); @@ -98,6 +99,41 @@ jQuery(function ($) { }) } + + function change_sort_box() { + let parent_selector = $('.list-orders-inner'); + let parent_selector_size = parent_selector.length; + let s_radio = $('.sort_menu'); + let s_box = $('.sort_box'); + + s_box.hide().find('input').each(function () { + $(this).prop('disabled', true); + }); + + for (let i = 0; i < parent_selector_size; i++) { + let my_target = $('.list-orders-inner:eq(' + i + ')'); + let default_index = my_target.find('.sort_menu_list').data('order_target') - 1; + if (typeof default_index !== "undefined") { + my_target.find('.sort_box:eq(' + default_index + ')').show().find('input').prop('disabled', false); + } else if (isNaN(default_index)) { + my_target.find('.sort_box:eq(0)').show().find('input').prop('disabled', false); + } + } + + s_radio.on('click', function () { + let target_index = $(this).val() - 1; + $(this).parents('.list-orders-inner') + .find('.sort_box').hide() + .find('input').each(function () { + $(this).prop('disabled', true); + }); + $(this).parents('.list-orders-inner') + .find('.sort_box:eq(' + target_index + ')').show() + .find('input').prop('disabled', false); + }) + } + + function select_tax() { let select_cat_checkbox = $('.select_cat_checkbox'); let input_chk_size = select_cat_checkbox.length; @@ -112,7 +148,7 @@ jQuery(function ($) { } } - select_cat_checkbox.click(function () { + select_cat_checkbox.on('click', function () { let checked = $(this).prop('checked'); if (checked) { $(this).parent().parent().siblings('.select_per_page').show(200); @@ -133,7 +169,7 @@ jQuery(function ($) { per_page_input.prop('disabled', false); } - per_page_cat.click(function () { + per_page_cat.on('click', function () { if ($(this).val() != 'default' && $(this).val() != '-1' && $(this).val() != 'all') { per_page_input.prop('disabled', false); } else { @@ -157,7 +193,7 @@ jQuery(function ($) { } } - $('.per_page_cat').click(function () { + $('.per_page_cat').on('click', function () { if ($(this).hasClass('set_number')) { $(this).siblings('.per_page_cat_input').prop('disabled', false); } else { diff --git a/template/order.php b/template/order.php index 5834128..2a0734e 100644 --- a/template/order.php +++ b/template/order.php @@ -1,12 +1,5 @@ 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' ) ); -$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' ); +$submit_type = APOP_UI::input_post_filter( 'submit_type', 'str' ); ?>

    並べ替え

    @@ -22,163 +15,99 @@ $apop_normal_check = APOP_UI::get_order_type( '_apop_normal_order' );
    - -
    +
    +

    通常

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

    -
    - -
    +
    +

    検索

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

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

    name; ?>

    -
      - -
    - -

    -
    -
    - - - - -
    - +
    + APOP_UI::get_cat_tag_list( 'cat', 'category' ) ); + $tax_title_text = 'カテゴリー'; + $submit_type_number = 2; + ?> + +
    - $tax_list ) : ?> -
    - 0 ): ?> - - -
    -
    - -

    name; ?>

    -
      - -
    - -

    -
    -
    - - - - -
    - +
    + APOP_UI::get_cat_tag_list( 'tag', 'post_tag' ) ); + $tax_title_text = 'タグ'; + $submit_type_number = 3; + ?> + +
    - $taxonomy_list ): ?> -
    - - 0 ): ?> - - -
    -
    - -

    name; ?>

    -
      - -
    - -

    -
    -
    - - - - - - -
    - +
    + APOP_UI::get_cat_tag_list( 'tax', 'taxonomy' ) ); + $tax_title_text = 'カスタム分類'; + $submit_type_number = 4; + ?> + +
    \ No newline at end of file diff --git a/template/order_parts_menu.php b/template/order_parts_menu.php new file mode 100644 index 0000000..2d10a3e --- /dev/null +++ b/template/order_parts_menu.php @@ -0,0 +1,11 @@ + +
      +
    • +
    • +
    + + $tax_list ) : ?> +
    + 0 ): ?> + + +
    +
    + +

    name; ?>

    + term_id ] ) ) { + $order_target = $order_target_data[ $tax_data->term_id ]; + } else { + $order_target = 1; + } + ?> +
      +
    • + +
    • +
    • + +
    • +
    + +
    +
      + +
    +
    +
    + term_id ); ?> + +
      + +
    + +
    + +

    + +
    +
    + + + + +
    + + $orders ) { if ( $orders['use'] == 1 ) { - $orderby[ $order_col ] = $sort_param[ $orders['sort'] ]; + if ( $order_col == 'custom_field' ) { + $this->set_custom_filed_sort( $orderby, $query, $order_col, $orders, $sort_param ); + } else { + $orderby[ $order_col ] = $sort_param[ $orders['sort'] ]; + } } } if ( isset( $orderby ) ) { @@ -93,11 +102,20 @@ if ( ! trait_exists( 'APOP_ORDER_SETTING' ) ) { $this->set_per_page( $query, 'search' ); } + private function set_custom_filed_sort( &$orderby, $query, $order_col, $orders, $sort_param ) { + if ( $order_col == 'custom_field' ) { + $meta_key = $orders['field']['meta_key']; + $orderby_key = $orders['field']['value_type']; + $orderby_sort = $orders['sort']; + $orderby[ $orderby_key ] = $sort_param[ $orderby_sort ]; + $query->set( 'meta_query', self::get_all_post_args( $meta_key ) ); + } + } + private function set_orderby( $query, $id, $target, $order_key ) { $order_settings = get_option( '_apop_' . $order_key . '_order' ); if ( isset( $order_settings['target_cat'][ $id ] ) && $order_settings['target_cat'][ $id ] == 1 ) { $sort_meta_key = '_apop_post_' . $target . '_' . $id; - //$query->set( 'meta_key', $sort_meta_key ); $query->set( 'meta_query', self::get_all_post_args( $sort_meta_key ) ); $query->set( 'orderby', array( 'meta_value_num' => 'ASC' ) ); $this->set_per_page( $query, self::get_per_page_tag( $target ), $id );