diff --git a/.idea/.gitignore b/.idea/.gitignore
deleted file mode 100644
index af2f81c..0000000
--- a/.idea/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-# デフォルトの無視ファイル
-/shelf/
-/workspace.xml
-# データソースのローカルストレージがファイルを無視しました
-/dataSources/
-/dataSources.local.xml
-# エディターベースの HTTP クライアントリクエスト
-/httpRequests/
diff --git a/.idea/modules.xml b/.idea/modules.xml
index baef841..1751034 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -2,7 +2,7 @@
-
+
\ No newline at end of file
diff --git a/.idea/nb-post-sort-cat-order.iml b/.idea/nb-post-sort-cat-order.iml
deleted file mode 100644
index c956989..0000000
--- a/.idea/nb-post-sort-cat-order.iml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/archive-post-oder-plus.php b/archive-post-oder-plus.php
index 2b306d1..e2e03b7 100644
--- a/archive-post-oder-plus.php
+++ b/archive-post-oder-plus.php
@@ -22,10 +22,6 @@ License: GPLv2
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-//初期化
-require_once __DIR__ . '/class/class.apop.activate.php';
-register_activation_hook( __FILE__, array( 'apop_activate', 'add_sort_posts' ) );
-
//メイン処理のクラスをインスタンス化
require_once __DIR__ . '/class/class.apop.order.php';
require_once __DIR__ . '/class/class.apop.ui.php';
diff --git a/class/class.apop.activate.php b/class/class.apop.activate.php
deleted file mode 100644
index 4df132d..0000000
--- a/class/class.apop.activate.php
+++ /dev/null
@@ -1,42 +0,0 @@
-term_id );
- foreach ( $posts as $post ) {
- self::create_sort_field( $post->ID, $category->term_id );
- }
- }
- }
-
- //カテゴリーの投稿を取得する
- public static function get_category_posts( $cat_id ) {
- $args = array(
- 'post_status' => array( 'publish', 'draft' ),
- 'posts_per_page' => - 1,
- 'category' => $cat_id,
- );
-
- return get_posts( $args );
- }
-
- /**
- * ソート用のカスタムフィールド作成
- *
- * @param $post_id
- * @param $cat_id
- */
- public static function create_sort_field( $post_id, $cat_id ) {
- $sort_key = '_apop_post_sort_' . $cat_id;
- //カスタムフィールドが存在しなければ追加する
- $sort_filed = get_post_meta( $post_id, $sort_key, true );
- if ( empty( $sort_filed ) ) {
- update_post_meta( $post_id, $sort_key, 0 );
- }
- }
-
-}
\ No newline at end of file
diff --git a/class/class.apop.order.php b/class/class.apop.order.php
index 65686aa..0cd1d56 100644
--- a/class/class.apop.order.php
+++ b/class/class.apop.order.php
@@ -1,8 +1,4 @@
update_post_sort( 'category' );
+ require_once self::TEMPLATE_DIR . 'success.php';
+ }
+
+ //タグの投稿表示順設定
+ if ( isset( $_POST['_apop_post_post_tag'] ) ) {
+ check_admin_referer( 'sh_options' );
$this->update_post_sort( 'post_tag' );
require_once self::TEMPLATE_DIR . 'success.php';
}
+ //カスタム分類の投稿表示順設定
+ if ( isset( $_POST['_apop_post_tax'] ) ) {
+ check_admin_referer( 'sh_options' );
+ $this->update_post_sort( 'tax' );
+ require_once self::TEMPLATE_DIR . 'success.php';
+ }
+
require_once self::TEMPLATE_DIR . 'order.php';
}
@@ -88,7 +96,7 @@ if ( ! class_exists( 'APOP' ) ) {
}
}
-
}
+
}
diff --git a/class/class.apop.ui.php b/class/class.apop.ui.php
index 2949e84..b64e161 100644
--- a/class/class.apop.ui.php
+++ b/class/class.apop.ui.php
@@ -3,71 +3,166 @@
class APOP_UI {
public static function get_all_taxonomies( $key ) {
- if($key !== 'taxonomy'){
+ if ( $key !== 'taxonomy' ) {
return get_terms( array( 'taxonomy' => $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' => 'カスタム分類',
- );
+ public static function get_cat_tag_list( $target, $key ): array {
+ $opt = get_option( '_apop_' . $target . '_order' );
- return $tax_names[ $tax_key ];
+ 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 );
+ }
}
- 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,
+ 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' => $include_tax,
+ 'include' => $tax_id,
);
+ $tax_data[] = get_terms( $args );
- return 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 get_sort_post_list( $tax_id, $search_param, $tax_key ) {
+ 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 ) . '
+taxonomy, $tax_key ) . '[post_sort][' . $tax_data->term_id . '][' . $target_post->ID . ']"
+value="' . $sort_num . '">
+';
+ }
+
+ 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,
- $search_param => $tax_id,
'orderby' => 'meta_value_num',
'order' => 'ASC',
- 'meta_key' => '_apop_post_' . $tax_key . '_' . $tax_id,
+ '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 );
}
- public static function get_none_sort_post_list( $tax_id, $key, $exclude_posts ) {
- $exclude = implode( ',', $exclude_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 ) . '
+taxonomy, $tax_key ) . '[post_sort][' . $tax_data->term_id . '][' . $target_post_no_order->ID . ']"
+value="' . $sort_num_no_order . '">
+';
+ }
+ 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,
- $key => $tax_id,
- ];
+ );
+
+ $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 );
}
+
}
\ No newline at end of file
diff --git a/css/apop-style.css b/css/apop-style.css
index e6ce059..1513b5a 100644
--- a/css/apop-style.css
+++ b/css/apop-style.css
@@ -5,32 +5,35 @@
margin-bottom: 0;
}
-.post-order-box {
- width: 95%;
- margin: 2em 0;
-
-}
-
.post-order-nav li {
width: 20em;
+ margin-right: .5em;
+ margin-bottom: 0;
padding: .5em;
- margin-bottom: -1px;
- font-size: 18px;
text-align: center;
- background: #2c2c2e;
- color: #fff;
+ background: #ababab;
+ border: 1px solid #999;
cursor: pointer;
- border-top-right-radius: 6px;
- border-top-left-radius: 6px;
- opacity: .5;
}
.post-order-nav li.en {
+ background: #fff;
+ border-bottom: 1px solid #fff;
opacity: 1;
}
-.post-order-nav li:first-child {
- margin-right: .3em;
+.post-order-nav li:last-child {
+ margin-right: 0;
+}
+
+.post-order-box-outer {
+ width: 95%;
+ margin: -1px 0 2em;
+ border-top: 1px solid #999;
+}
+
+.post-order-box:not(:first-child) {
+ display: none;
}
h3 {
@@ -47,10 +50,17 @@ h3 {
}
.list-orders-inner {
- width: calc((100% - 10px) / 3);
- border: 1px solid #999;
- background: #fff;
+ width: calc((100% - 10px) / 5);
+ margin-right: .5em;
padding: .5em;
+ border: 1px solid #999;
+ position: relative;
+}
+
+p.submit.post-order .button-primary {
+ position: absolute;
+ bottom: 1em;
+ right: 1.5em;
}
.post-order-list {
@@ -60,9 +70,14 @@ h3 {
.product-list {
padding: .5em;
border-radius: 4px;
- background: #2271B1;
+ background: #fff;
cursor: move;
- color: #fff;
+ color: #4b4b4b;
+ border: 1px solid #ababab;
+}
+
+.product-list.no_order {
+ background: #ababab;
}
.list_order {
diff --git a/js/apop-style.js b/js/apop-style.js
index 56ec788..0e4791a 100644
--- a/js/apop-style.js
+++ b/js/apop-style.js
@@ -18,5 +18,15 @@ jQuery(function ($) {
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();
+ }
+ });
+
});
\ No newline at end of file
diff --git a/readme.txt b/readme.txt
index 36d84d6..45c59da 100644
--- a/readme.txt
+++ b/readme.txt
@@ -12,14 +12,14 @@ License URI: https://www.gnu.org/licenses/gpl-2.0.html
== Description ==
-このプラグインはアーカイブページの投稿表示順をタクソノミー毎に設定するプラグインです。
+このプラグインはタクソノミー毎に投稿表示順を設定するプラグインです。
= 仕様 =
投稿表示順をカスタマイズしたいタクソノミーを選択します。
-選択した各タクソノミー内の投稿位置をドラッグ&ドロップで変え、保存することでタクソノミー毎の表示順が変更できます。
+選択した各タクソノミー内の投稿順をドラッグ&ドロップで変更し保存します。
-【専用コード】
-表示したい箇所のPHPファイルに下記のコードを記述することで表示順を変更することが可能です。
+【サブクエリコード】
+get_posts()などを利用する場合、下記のコードに並び順のパラメータを取得できます。
diff --git a/template/order.php b/template/order.php
index f1978ad..cb72885 100644
--- a/template/order.php
+++ b/template/order.php
@@ -1,53 +1,94 @@
APOP_UI::get_cat_tag_list( 'cat', 'category' ),
- 'tag_id' => APOP_UI::get_cat_tag_list( 'tag', 'post_tag' ),
-);
+$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' ) );
?>
-