diff --git a/archive-post-oder-plus.php b/archive-post-oder-plus.php
index e2e03b7..2db47bf 100644
--- a/archive-post-oder-plus.php
+++ b/archive-post-oder-plus.php
@@ -25,6 +25,7 @@ License: GPLv2
//メイン処理のクラスをインスタンス化
require_once __DIR__ . '/class/class.apop.order.php';
require_once __DIR__ . '/class/class.apop.ui.php';
+
$APOP = new APOP;
//CSS, JSの読み込み
@@ -34,4 +35,6 @@ function register_my_styles() {
wp_enqueue_style( 'hrc_post_style', $plugin_url . 'css/apop-style.css' );
wp_enqueue_script( 'jquery-ui-sortable' );
wp_enqueue_script( 'post-sort-cat-order_js', $plugin_url . 'js/apop-style.js' );
-}
\ No newline at end of file
+}
+
+$APOP->set_query();
diff --git a/class/class.apop.order.php b/class/class.apop.order.php
index 0cd1d56..2d253e1 100644
--- a/class/class.apop.order.php
+++ b/class/class.apop.order.php
@@ -4,9 +4,12 @@ if ( ! defined( 'ABSPATH' ) ) {
} // Exit if accessed directly
if ( ! class_exists( 'APOP' ) ) {
+ require_once __DIR__ . '/../util/apop-order-setting.php';
class APOP {
+ use APOP_ORDER_SETTING;
+
const TEMPLATE_DIR = __DIR__ . '/../template/';
public function __construct() {
@@ -19,17 +22,25 @@ if ( ! class_exists( 'APOP' ) ) {
'APO +',
'level_8',
'apop_post_sort',
- array( $this, 'show_option_page' ),
+ array( $this, 'display_setting_page' ),
'',
50
);
+ add_submenu_page(
+ 'apop_post_sort', // parent_slug
+ 'Sort taxonomy', // page_title
+ '設定', // menu_title
+ 'administrator', // capability
+ 'apop_post_sort', // menu_slug
+ array( $this, 'display_setting_page' ) // function
+ );
add_submenu_page(
'apop_post_sort', // parent_slug
'Select taxonomy', // page_title
- 'タクソノミー選択', // menu_title
+ '並べ替え', // menu_title
'administrator', // capability
'apop_post_sort_setting', // menu_slug
- array( $this, 'display_setting_page' ) // function
+ array( $this, 'show_option_page' ) // function
);
}
@@ -42,15 +53,14 @@ if ( ! class_exists( 'APOP' ) ) {
$settings = array(
'_apop_cat_order', //カテゴリー設定
+ '_apop_per_page', //1ページ表示件数
'_apop_tag_order', //タグ設定
'_apop_tax_order', //カスタムタクソノミー設定
);
-
foreach ( $settings as $setting ) {
$opt = $_POST[ $setting ];
update_option( $setting, $opt );
}
-
require_once self::TEMPLATE_DIR . 'success.php';
}
@@ -60,6 +70,20 @@ if ( ! class_exists( 'APOP' ) ) {
public function show_option_page() {
+
+ //検索の投稿表示順設定
+ if ( isset( $_POST['_apop_post_search'] ) ) {
+ check_admin_referer( 'sh_options' );
+ $this->update_search_sort( 'search' );
+ require_once self::TEMPLATE_DIR . 'success.php';
+ }
+
+ if ( isset( $_POST['_apop_search_order'] ) ) {
+ check_admin_referer( 'sh_options' );
+ update_option( '_apop_search_order', $_POST['_apop_search_order'] );
+ require_once self::TEMPLATE_DIR . 'success.php';
+ }
+
//カテゴリーの投稿表示順設定
if ( isset( $_POST['_apop_post_category'] ) ) {
check_admin_referer( 'sh_options' );
@@ -96,6 +120,13 @@ if ( ! class_exists( 'APOP' ) ) {
}
}
+ private function update_search_sort() {
+ $posts_sort = $_POST['_apop_post_search']['post_sort'];
+ foreach ( $posts_sort as $post_id => $sort ) {
+ update_post_meta( $post_id, '_apop_post_search', $sort );
+ }
+ }
+
}
}
diff --git a/class/class.apop.ui.php b/class/class.apop.ui.php
index b64e161..8af4326 100644
--- a/class/class.apop.ui.php
+++ b/class/class.apop.ui.php
@@ -1,168 +1,209 @@
$key, 'get' => 'all' ) );
+ public static function get_all_search_posts( $type, $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_search';
+ } else {
+ $exclude = implode( ',', $exclude_posts );
+ if ( ! empty( $exclude ) ) {
+ $args['exclude'] = $exclude;
+ }
+ }
+ return get_posts( $args );
}
- return get_taxonomies( array( 'public' => true, '_builtin' => false ) );
- }
- public static function get_cat_tag_list( $target, $key ): array {
- $opt = get_option( '_apop_' . $target . '_order' );
+ public static function get_all_taxonomies( $key ) {
+ if ( $key !== 'taxonomy' ) {
+ return get_terms( array( 'taxonomy' => $key, 'get' => 'all' ) );
+ }
+
+ return get_taxonomies( array( 'public' => true, '_builtin' => false ) );
+ }
+
+ public static function get_cat_tag_list( $target, $key ): array {
+ $opt = get_option( '_apop_' . $target . '_order' );
+
+ if ( ! isset( $opt['target_cat'] ) ) {
+ return array();
+ }
+
+ if ( $key == 'taxonomy' ) {
+ return self::create_custom_tax_term( $opt );
+ } else {
+ return self::create_tax_term( $opt, $key );
+ }
+ }
+
+ private static function create_custom_tax_term( $opt ): array {
+ $tax_data = [];
+ foreach ( $opt['target_cat'] as $tax_id => $status ) {
+ //フラグが立っているカスタムタクソノミーは情報を取得する
+ if ( $status ) {
+ $args = array(
+ 'taxonomy' => get_term( $tax_id )->taxonomy,
+ 'hide_empty' => 0,
+ 'include' => $tax_id,
+ );
+ $tax_data[] = get_terms( $args );
+
+ }
+ }
+
+ return $tax_data;
+ }
+
+ private static function create_tax_term( $opt, $key ) {
+ $include = array();
+ foreach ( $opt['target_cat'] as $tax_id => $status ) {
+ //フラグが立っているタクソノミーIDを取得
+ if ( $status ) {
+ $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 );
+ }
- if ( ! isset( $opt['target_cat'] ) ) {
return array();
}
- if ( $key == 'taxonomy' ) {
- return self::create_custom_tax_term( $opt );
- } else {
- return self::create_tax_term( $opt, $key );
- }
- }
-
- private static function create_custom_tax_term( $opt ): array {
- $tax_data = [];
- foreach ( $opt['target_cat'] as $tax_id => $status ) {
- //フラグが立っているカスタムタクソノミーは情報を取得する
- if ( $status ) {
- $args = array(
- 'taxonomy' => get_term( $tax_id )->taxonomy,
- 'hide_empty' => 0,
- 'include' => $tax_id,
- );
- $tax_data[] = get_terms( $args );
-
- }
- }
-
- return $tax_data;
- }
-
- private static function create_tax_term( $opt, $key ) {
- $include = array();
- foreach ( $opt['target_cat'] as $tax_id => $status ) {
- //フラグが立っているタクソノミーIDを取得
- if ( $status ) {
- $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 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[] = '
+ 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 ) . '
';
- }
+ }
- return array(
- implode( PHP_EOL, $list ),
- $exclude_posts,
- $sort_num,
- );
-
- }
-
- private static function get_sort_post_list( $tax_id, $search_param, $tax_name ) {
- $args = [
- '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,
- ];
-
-
- self::create_post_tax_query( $args, $search_param, $tax_name, $tax_id );
-
- return get_posts( $args );
- }
-
- private static function create_post_sort_key( $tax_name, $tax_key ) {
- if ( $tax_key == 'taxonomy' ) {
- return 'tax';
- }
-
- return $tax_name;
- }
-
- private static function create_post_tax_query( &$args, $key, $tax_name, $tax_id ) {
- if ( $key == 'taxonomy' ) {
- $args['tax_query'] = array(
- array(
- 'taxonomy' => $tax_name,
- 'field' => 'term_id',
- 'terms' => $tax_id,
- 'include_children' => false
- )
+ return array(
+ implode( PHP_EOL, $list ),
+ $exclude_posts,
+ $sort_num,
);
- } else {
- $args[ $key ] = $tax_id;
- }
- }
- 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[] = '
+ }
+
+ private static function get_sort_post_list( $tax_id, $search_param, $tax_name ) {
+ $args = [
+ '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,
+ ];
+
+
+ self::create_post_tax_query( $args, $search_param, $tax_name, $tax_id );
+
+ return get_posts( $args );
+ }
+
+ private static function create_post_sort_key( $tax_name, $tax_key ) {
+ if ( $tax_key == 'taxonomy' ) {
+ return 'tax';
+ }
+
+ return $tax_name;
+ }
+
+ private static function create_post_tax_query( &$args, $key, $tax_name, $tax_id ) {
+ if ( $key == 'taxonomy' ) {
+ $args['tax_query'] = array(
+ array(
+ 'taxonomy' => $tax_name,
+ 'field' => 'term_id',
+ 'terms' => $tax_id,
+ 'include_children' => false
+ )
+ );
+ } else {
+ $args[ $key ] = $tax_id;
+ }
+ }
+
+ 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 );
+ }
}
- if ( isset( $list ) ) {
- return implode( PHP_EOL, $list );
- }
+
+ return '';
}
- return '';
- }
+ private static function get_none_sort_post_list( $tax_id, $search_param, $exclude_posts, $tax_name ) {
- 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,
+ );
- $args = array(
- 'post_status' => array( 'publish', 'draft' ),
- 'posts_per_page' => - 1,
- );
+ $exclude = implode( ',', $exclude_posts );
+ if ( ! empty( $exclude ) ) {
+ $args['exclude'] = $exclude;
+ }
- $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 );
}
- self::create_post_tax_query( $args, $search_param, $tax_name, $tax_id );
+ public static function create_cat_per_page( $opt_per_page, $type ): array {
+ $cat_per_page = $opt_per_page[ $type ] ?? 'default';
+ $set = '';
+ $cat_per_page_num = '';
+ if ( isset( $opt_per_page[ $type ] ) ) {
+ if ( $opt_per_page[ $type ] != 'default' && $opt_per_page[ $type ] != '-1' ) {
+ $set = ' checked="checked"';
+ $cat_per_page_num = $cat_per_page;
+ }
+ }
- return get_posts( $args );
+ return array(
+ '_per_page' => $cat_per_page,
+ '_set' => $set,
+ '_per_page_num' => $cat_per_page_num,
+ );
+ }
}
-
-
}
\ No newline at end of file
diff --git a/css/apop-style.css b/css/apop-style.css
index 1513b5a..f6b7bd8 100644
--- a/css/apop-style.css
+++ b/css/apop-style.css
@@ -51,18 +51,50 @@ h3 {
.list-orders-inner {
width: calc((100% - 10px) / 5);
- margin-right: .5em;
+ margin: 1.5em 1em 0 0;
padding: .5em;
border: 1px solid #999;
position: relative;
}
+.list-orders-inner.search_inner {
+ width: calc((100% - 10px) / 2);
+}
+
+.apop_search_order_target {
+ display: flex;
+}
+
+.apop_search_order_target li:first-child{
+ margin-right: 2em;
+}
+
p.submit.post-order .button-primary {
position: absolute;
bottom: 1em;
right: 1.5em;
}
+dl.post_per_page_list {
+ width: 100%;
+}
+
+dl.post_per_page_list dt {
+ float: left;
+}
+
+dl.post_per_page_list dd {
+ margin-left: 200px;
+}
+
+dl.post_per_page_list dd:first-of-type {
+ margin-bottom: 2em;
+}
+
+.form-table tr {
+ border-bottom: 1px solid #ccc;
+}
+
.post-order-list {
margin: .5em 1em 1em 0;
}
@@ -90,4 +122,8 @@ p.submit.post-order .button-primary {
.sort-num-label::after {
content: "]";
+}
+
+.per_page_cat_input {
+
}
\ No newline at end of file
diff --git a/js/apop-style.js b/js/apop-style.js
index 0e4791a..8e20973 100644
--- a/js/apop-style.js
+++ b/js/apop-style.js
@@ -1,32 +1,109 @@
jQuery(function ($) {
- let cat_ul_count = $('.post-order-list').length; //カテゴリ総数
- for (let i = 0; i < cat_ul_count; i++) {
- let my_list = $('.post-order-list:eq(' + i + ')');
- my_list.sortable(
- {
- update: function () {
- let list_count = $('.product-list', my_list).length;
- for (let j = 0; j < list_count; j++) {
- let list_order = j + 1;
- $('.list_order:eq(' + j + ')', my_list).val(list_order);
- $('.list_order:eq(' + j + ')', my_list).siblings('.sort-num-label').text(list_order);
- }
- }
+ change_tab_menu();
+ order_list();
+
+ change_search_per_page();
+ change_search_order_options();
+ change_cat_per_page();
+ change_tag_per_page();
+ change_tax_per_page();
+
+
+ function change_tab_menu() {
+ let submit_type = $('.post-order-box-outer').data('submit_type');
+ let order_nav_list = $('.post-order-nav li');
+ let order_box = $('.post-order-box');
+
+ order_nav_list.removeClass('en');
+ order_box.hide();
+ $('.post-order-nav li:eq(' + submit_type + ')').addClass('en');
+ $('.post-order-box:eq(' + submit_type + ')').show()
+
+ order_nav_list.click(function () {
+ if (!$(this).hasClass('en')) {
+ let target_index = $(this).index();
+ order_nav_list.removeClass('en');
+ $(this).addClass('en');
+ order_box.hide();
+ $('.post-order-box:eq(' + target_index + ')').show();
}
- );
- my_list.disableSelection();
+ });
}
- $('.post-order-nav li').click(function () {
- if (!$(this).hasClass('en')) {
- let target_index = $(this).index();
- $('.post-order-nav li').removeClass('en');
- $(this).addClass('en');
- $('.post-order-box').hide();
- $('.post-order-box:eq(' + target_index + ')').show();
+ function order_list() {
+ let cat_ul_count = $('.post-order-list').length; //カテゴリ総数
+ for (let i = 0; i < cat_ul_count; i++) {
+ let my_list = $('.post-order-list:eq(' + i + ')');
+ my_list.sortable(
+ {
+ update: function () {
+ let list_count = $('.product-list', my_list).length;
+ for (let j = 0; j < list_count; j++) {
+ let list_order = j + 1;
+ $('.list_order:eq(' + j + ')', my_list).val(list_order);
+ $('.list_order:eq(' + j + ')', my_list).siblings('.sort-num-label').text(list_order);
+ }
+ }
+ }
+ );
+ my_list.disableSelection();
}
- });
+ }
+ function change_search_per_page() {
+ let per_page_cat = $('.per_page_search');
+ let per_page_input = $('.per_page_search_input');
+ change_per_page(per_page_cat, per_page_input);
+ }
+
+ function change_cat_per_page() {
+ let per_page_cat = $('.per_page_cat');
+ let per_page_input = $('.per_page_cat_input');
+ change_per_page(per_page_cat, per_page_input);
+ }
+
+ function change_tag_per_page() {
+ let per_page_cat = $('.per_page_tag');
+ let per_page_input = $('.per_page_tag_input');
+ change_per_page(per_page_cat, per_page_input);
+ }
+
+ function change_tax_per_page() {
+ let per_page_cat = $('.per_page_tax');
+ let per_page_input = $('.per_page_tax_input');
+ change_per_page(per_page_cat, per_page_input);
+ }
+
+ function change_per_page(per_page_cat, per_page_input) {
+ if (per_page_input.val() == '') {
+ per_page_input.prop('disabled', true);
+ } else {
+ per_page_input.prop('disabled', false);
+ }
+ per_page_cat.click(function () {
+ if ($(this).val() == 'set') {
+ per_page_input.prop('disabled', false);
+ } else {
+ per_page_input.val('');
+ per_page_input.prop('disabled', true);
+ }
+ })
+ }
+
+ function change_search_order_options() {
+ let s_radio = $('.apop_search_order');
+ let s_box = $('.search_sort_box');
+ let default_index = $('.apop_search_order_target').data('search_order_target') - 1;
+
+ s_box.hide();
+ $('.search_sort_box:eq(' + default_index + ')').show();
+
+ s_radio.click(function () {
+ let target_index = $(this).val() - 1;
+ s_box.hide();
+ $('.search_sort_box:eq(' + target_index + ')').show();
+ })
+ }
});
\ No newline at end of file
diff --git a/template/order.php b/template/order.php
index cb72885..f922215 100644
--- a/template/order.php
+++ b/template/order.php
@@ -1,18 +1,150 @@
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' ) );
+$search_lists = APOP_UI::get_all_search_posts( 'registered' );
+$category_lists = array( 'category' => 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 = $_POST['submit_type'] ?? '0';
+$apop_search_order = get_option( '_apop_search_order' ) ?? '1';
?>
+並べ替え
-
+
+
-
カテゴリー
$tax_list ) : ?>
0 ): $exclude_posts = []; ?>
@@ -28,8 +160,9 @@ $taxonomy_lists = array( 'taxonomy' => APOP_UI::get_cat_tag_list( 'tax', 'taxono
echo APOP_UI::create_product_none_order_list( $tax_data, $tax_key, $exclude_posts, $sort_num );
?>
+
+ value="変更を保存"/>
@@ -38,7 +171,6 @@ $taxonomy_lists = array( 'taxonomy' => APOP_UI::get_cat_tag_list( 'tax', 'taxono
-
タグ
$tax_list ) : ?>
0 ): $exclude_posts = []; ?>
@@ -54,8 +186,9 @@ $taxonomy_lists = array( 'taxonomy' => APOP_UI::get_cat_tag_list( 'tax', 'taxono
echo APOP_UI::create_product_none_order_list( $tax_data, $tax_key, $exclude_posts, $sort_num );
?>
+
+ value="変更を保存"/>
@@ -64,7 +197,6 @@ $taxonomy_lists = array( 'taxonomy' => APOP_UI::get_cat_tag_list( 'tax', 'taxono
-
カスタム分類
$taxonomy_list ): ?>
diff --git a/template/setting.php b/template/setting.php
index 23b37b5..9238947 100644
--- a/template/setting.php
+++ b/template/setting.php
@@ -8,35 +8,92 @@ $all_tax = APOP_UI::get_all_taxonomies( 'taxonomy' );