Merge pull request 'WP PLUGIN アーカイブページの投稿表示順設定' (#2) from 修正_タクソノミー関連 into master

Reviewed-on: https://develop.n-k-y.net/repo/WP_PLUGIN/POST_ORDER_BY_ARCHIVE/pulls/2
This commit was merged in pull request #2.
This commit is contained in:
nobu
2021-05-09 18:12:47 +09:00
8 changed files with 205 additions and 263 deletions
+5 -3
View File
@@ -22,6 +22,9 @@ License: GPLv2
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
define( 'APOP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'APOP_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
//メイン処理のクラスをインスタンス化
require_once __DIR__ . '/class/class.apop.order.php';
require_once __DIR__ . '/class/class.apop.ui.php';
@@ -31,10 +34,9 @@ $APOP = new APOP;
//CSS, JSの読み込み
add_action( 'admin_enqueue_scripts', 'register_my_styles' );
function register_my_styles() {
$plugin_url = plugin_dir_url( __FILE__ );
wp_enqueue_style( 'hrc_post_style', $plugin_url . 'css/apop-style.css' );
wp_enqueue_style( 'hrc_post_style', APOP_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' );
wp_enqueue_script( 'post-sort-cat-order_js', APOP_PLUGIN_URL . 'js/apop-style.js' );
}
$APOP->set_query();
+44 -4
View File
@@ -32,7 +32,7 @@ if ( ! class_exists( 'APOP_UI' ) ) {
return implode( PHP_EOL, $list );
}
private static function crate_non_registerd_mark( $no_order ) {
private static function crate_non_registerd_mark( $no_order ): string {
if ( ! empty( $no_order ) ) {
return '■';
}
@@ -44,6 +44,8 @@ if ( ! class_exists( 'APOP_UI' ) ) {
return array(
'post_status' => array( 'publish', 'draft' ),
'posts_per_page' => - 1,
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
'relation' => 'OR',
array(
@@ -58,13 +60,20 @@ if ( ! class_exists( 'APOP_UI' ) ) {
);
}
public static function get_all_taxonomies( $key ) {
private static function get_all_taxonomies( $key ) {
if ( $key !== 'taxonomy' ) {
return get_terms( array( 'taxonomy' => $key, 'get' => 'all' ) );
}
$all_custom_tax = get_taxonomies( array( 'public' => true, '_builtin' => false ) );
$custom_tax_list = [];
foreach ( $all_custom_tax as $custom_tax ) {
$custom_tax_list = array_merge( $custom_tax_list, get_terms( array(
'taxonomy' => $custom_tax,
'get' => 'all'
) ) );
}
return get_taxonomies( array( 'public' => true, '_builtin' => false ) );
return $custom_tax_list;
}
public static function get_cat_tag_list( $target, $key ): array {
@@ -221,6 +230,37 @@ value="' . $sort_num . '">
);
}
public static function disp_tax_setting( $key, $title, $order_name ) {
$tax_data = APOP_UI::get_all_taxonomies( $key );
if ( count( $tax_data ) > 0 ) {
$order_name = $order_name;
$order_tax = $key == 'post_tag' ? 'tag' : $key;
echo '<tr><th scope="row">' . $title . '設定</th><td>';
include APOP_PLUGIN_PATH . 'template/setting_parts_taxonomy.php';
echo '</td></tr>';
}
}
public static function create_tax_per_page( $opt_per_page, $type, $id ): array {
$cat_per_page = $opt_per_page[ $type ][ $id ] ?? 'default';
$checked = '';
$cat_per_page_num = '';
if ( isset( $opt_per_page[ $type ][ $id ] ) ) {
if ( $opt_per_page[ $type ][ $id ] != 'default'
&& $opt_per_page[ $type ][ $id ] != '-1'
&& $opt_per_page[ $type ][ $id ] != 'all' ) {
$checked = ' checked="checked"';
$cat_per_page_num = $cat_per_page;
}
}
return array(
'_per_page' => $cat_per_page,
'_checked' => $checked,
'_per_page_num' => $cat_per_page_num,
);
}
public static function create_search_normal_list( $type ): array {
$name_key = 'apop_' . $type . '_order_param';
$order_param = get_option( '_' . $name_key );
+13 -3
View File
@@ -58,7 +58,7 @@ h3 {
}
.list-orders-inner {
width: calc((100% - 10px) / 2);
width: 45%;;
margin: 1.5em 1em 0 0;
padding: .5em;
border: 1px solid #999;
@@ -66,7 +66,7 @@ h3 {
}
.list-orders-inner.search_inner {
width: calc((100% - 10px) / 2);
width: 50%;
}
.apop_normal_order_target,
@@ -82,7 +82,6 @@ h3 {
p.submit.post-order .button-primary {
position: absolute;
bottom: 1em;
right: 1.5em;
}
dl.apop_setting_list {
@@ -162,6 +161,17 @@ dl.apop_setting_list dd:first-of-type {
margin-top: 1em;
}
.order_setting_list > li {
padding: 1em;
border: 1px solid #ccc;
}
.select_per_page {
margin-top: 1em;
padding-top: 1em;
border-top: 1px solid #ccc;
}
@media only screen and (max-width: 1264px) {
.search_normal_sort .product-list {
display: block;
+46 -39
View File
@@ -10,12 +10,11 @@ jQuery(function ($) {
change_search_order();
change_normal_order();
//Tax select
select_tax();
//per page
disp_tax_per_page();
change_normal_per_page();
change_search_per_page();
change_cat_per_page();
change_tag_per_page();
change_tax_per_page();
@@ -99,56 +98,41 @@ jQuery(function ($) {
})
}
function disp_tax_per_page() {
let box_count = $('.order_setting_list').length;
for (let i = 0; i < box_count; i++) {
$('.order_setting_list:eq(' + i + ')').click(function () {
let en_count = $('.order_setting_list:eq(' + i + ') [name^="_apop_"]:checked').length;
if (en_count == 0) {
$(this).parent().next('dt').addClass('hide_list').next('dd').addClass('hide_list');
function select_tax() {
let select_cat_checkbox = $('.select_cat_checkbox');
let input_chk_size = select_cat_checkbox.length;
let i = 0;
for (i; i < input_chk_size; i++) {
let chk = $('.select_cat_checkbox:eq(' + i + '):checked').length;
if (chk == 1) {
$('.select_cat:eq(' + i + ')').siblings('.select_per_page').show();
} else {
$(this).parent().next('dt').removeClass('hide_list').next('dd').removeClass('hide_list');
}
});
$('.select_cat:eq(' + i + ')').siblings('.select_per_page').hide();
}
}
function change_normal_per_page() {
let per_page_cat = $('.per_page_normal');
let per_page_input = $('.per_page_normal_input');
change_per_page(per_page_cat, per_page_input);
select_cat_checkbox.click(function () {
let checked = $(this).prop('checked');
if (checked) {
$(this).parent().parent().siblings('.select_per_page').show(200);
} else {
$(this).parent().parent().siblings('.select_per_page').hide(200);
}
});
}
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() != 'default' && $(this).val() != '-1' && $(this).val() != 'all') {
per_page_input.prop('disabled', false);
@@ -159,4 +143,27 @@ jQuery(function ($) {
})
}
function change_tax_per_page() {
let set_number = $('.set_number');
let input_chk_size = set_number.length;
let i = 0;
for (i; i < input_chk_size; i++) {
let input_num_box = $('.set_number:eq(' + i + ')').siblings('.per_page_cat_input');
if (input_num_box.val() == '') {
input_num_box.prop('disabled', true);
} else {
input_num_box.prop('disabled', false);
}
}
$('.per_page_cat').click(function () {
if ($(this).hasClass('set_number')) {
$(this).siblings('.per_page_cat_input').prop('disabled', false);
} else {
$(this).parents('li').find('.per_page_cat_input').val('').prop('disabled', true);
}
});
}
});
+3 -2
View File
@@ -33,7 +33,7 @@ $apop_normal_check = APOP_UI::get_order_type( '_apop_normal_order' );
value="1"<?php checked( $apop_normal_check, 1 ); ?>>標準</label></li>
<li><label>
<input class="apop_normal_order" type="radio" name="_apop_normal_order"
value="2"<?php checked( $apop_normal_check, 2 ); ?>>カスタム</label></li>
value="2"<?php checked( $apop_normal_check, 2 ); ?>>ドラッグソート</label></li>
</ul>
<hr>
<div class="normal_sort_box">
@@ -72,7 +72,8 @@ $apop_normal_check = APOP_UI::get_order_type( '_apop_normal_order' );
value="1"<?php checked( $apop_search_order_check, 1 ); ?>>標準</label></li>
<li><label>
<input class="apop_search_order" type="radio" name="_apop_search_order"
value="2"<?php checked( $apop_search_order_check, 2 ); ?>>カスタム</label></li>
value="2"<?php checked( $apop_search_order_check, 2 ); ?>>ドラッグソート</label>
</li>
</ul>
<hr>
<div class="search_sort_box">
+3 -197
View File
@@ -1,17 +1,8 @@
<?php
$all_categories = APOP_UI::get_all_taxonomies( 'category' );
$all_tags = APOP_UI::get_all_taxonomies( 'post_tag' );
$all_tax = APOP_UI::get_all_taxonomies( 'taxonomy' );
?>
<div class="post-setting-box">
<form action="" method="post">
<?php
wp_nonce_field( 'sh_options' );
$opt_cat = get_option( '_apop_cat_order' );
$opt_per_page = get_option( '_apop_per_page' );
$opt_tag = get_option( '_apop_tag_order' );
$opt_tax = get_option( '_apop_tax_order' );
$default_per_page = get_option( 'posts_per_page' );
?>
<h2>設定</h2>
@@ -47,194 +38,9 @@ $all_tax = APOP_UI::get_all_taxonomies( 'taxonomy' );
</dl>
</td>
</tr>
<?php if ( count( $all_categories ) > 0 ): $disp = false; ?>
<tr>
<th scope="row">カテゴリー設定</th>
<td>
<dl class="apop_setting_list">
<dt>対象</dt>
<dd>
<ul class="order_setting_list">
<?php foreach ( $all_categories as $category ): ?>
<?php
$check_slug = $opt_cat['target_cat'][ $category->term_id ] ?? '';
APOP_UI::is_disp_per_page( $disp, $check_slug );
?>
<li>
<div class="select_cat">
<label>
<input type="hidden"
name="_apop_cat_order[target_cat][<?php echo $category->term_id; ?>]"
value="0">
<input type="checkbox"
name="_apop_cat_order[target_cat][<?php echo $category->term_id; ?>]"
<?php checked( $check_slug, 1 ); ?>
value="1">
<?php echo $category->name; ?>
</label>
</div>
</li>
<?php endforeach; ?>
</ul>
</dd>
<dt<?php echo APOP_UI::create_disp_class( $disp ); ?>>1ページ表示件数</dt>
<dd<?php echo APOP_UI::create_disp_class( $disp ); ?>>
<?php $per_page_data = APOP_UI::create_cat_per_page( $opt_per_page, 'category' ); ?>
<ul>
<li>
<label>
<input class="per_page_cat" type="radio" name="_apop_per_page[category]"
value="default"<?php checked( $per_page_data['_per_page'], 'default' ); ?>>表示設定に従う(<?php echo $default_per_page; ?>
件)</label>
</li>
<li><label>
<input class="per_page_cat" type="radio" name="_apop_per_page[category]"
value="all"<?php checked( $per_page_data['_per_page'], 'all' ); ?>>全体設定に従う</label>
</li>
<li><label>
<input class="per_page_cat" type="radio" name="_apop_per_page[category]"
value="-1"<?php checked( $per_page_data['_per_page'], '-1' ); ?>>全件</label>
</li>
<li>
<label><input class="per_page_cat" type="radio"
name="_apop_per_page[category]"
value=""<?php echo $per_page_data['_checked']; ?>>表示数設定
<input class="per_page_cat_input" type="text"
name="_apop_per_page[category]"
value="<?php echo $per_page_data['_per_page_num']; ?>" required>
</label>
</li>
</ul>
</dd>
</dl>
</td>
</tr>
<?php endif; ?>
<?php if ( count( $all_tags ) > 0 ): $disp = false; ?>
<tr>
<th scope="row">タグ設定</th>
<td>
<dl class="apop_setting_list">
<dt>対象</dt>
<dd>
<ul class="order_setting_list">
<?php foreach ( $all_tags as $tag ): ?>
<?php
$check_slug = $opt_tag['target_cat'][ $tag->term_id ] ?? '';
APOP_UI::is_disp_per_page( $disp, $check_slug );
?>
<li>
<div class="select_cat">
<label>
<input type="hidden"
name="_apop_tag_order[target_cat][<?php echo $tag->term_id; ?>]"
value="0">
<input type="checkbox"
name="_apop_tag_order[target_cat][<?php echo $tag->term_id; ?>]"
<?php checked( $check_slug, 1 ); ?>
value="1">
<?php echo $tag->name; ?>
</label>
</div>
</li>
<?php endforeach; ?>
</ul>
</dd>
<dt<?php echo APOP_UI::create_disp_class( $disp ); ?>>1ページ表示件数</dt>
<dd<?php echo APOP_UI::create_disp_class( $disp ); ?>><?php $per_page_data = APOP_UI::create_cat_per_page( $opt_per_page, 'tag' ); ?>
<ul>
<li>
<label>
<input class="per_page_tag" type="radio" name="_apop_per_page[tag]"
value="default"<?php checked( $per_page_data['_per_page'], 'default' ); ?>>表示設定に従う(<?php echo $default_per_page; ?>
件)</label>
</li>
<li><label>
<input class="per_page_tag" type="radio" name="_apop_per_page[tag]"
value="all"<?php checked( $per_page_data['_per_page'], 'all' ); ?>>全体設定に従う</label>
</li>
<li><label>
<input class="per_page_tag" type="radio" name="_apop_per_page[tag]"
value="-1"<?php checked( $per_page_data['_per_page'], '-1' ); ?>>全件</label>
</li>
<li>
<label><input class="per_page_tag" type="radio" name="_apop_per_page[tag]"
value=""<?php echo $per_page_data['_checked']; ?>>表示数設定
<input class="per_page_tag_input" type="text"
name="_apop_per_page[tag]"
value="<?php echo $per_page_data['_per_page_num']; ?>" required>
</label></li>
</ul>
</dd>
</dl>
</td>
</tr>
<?php endif; ?>
<?php
if ( count( $all_tax ) > 0 ): $disp = false; ?>
<tr>
<th scope="row">カスタム分類</th>
<td>
<dl class="apop_setting_list">
<dt>対象</dt>
<dd>
<ul class="order_setting_list">
<?php foreach ( $all_tax as $tax ): $all_taxs = APOP_UI::get_all_taxonomies( $tax ); ?>
<?php foreach ( $all_taxs as $tax ): ?>
<?php
$check_slug = $opt_tax['target_cat'][ $tax->term_id ] ?? '';
APOP_UI::is_disp_per_page( $disp, $check_slug );
?>
<li>
<div class="select_cat">
<label>
<input type="hidden"
name="_apop_tax_order[target_cat][<?php echo $tax->term_id; ?>]"
value="0">
<input type="checkbox"
name="_apop_tax_order[target_cat][<?php echo $tax->term_id; ?>]"
<?php checked( $check_slug, 1 ); ?>
value="1">
<?php echo $tax->name; ?>
</label>
</div>
</li>
<?php endforeach; ?>
<?php endforeach; ?>
</ul>
</dd>
<dt<?php echo APOP_UI::create_disp_class( $disp ); ?>>1ページ表示件数</dt>
<dd<?php echo APOP_UI::create_disp_class( $disp ); ?>>
<?php $per_page_data = APOP_UI::create_cat_per_page( $opt_per_page, 'tax' ); ?>
<ul>
<li>
<label>
<input class="per_page_tax" type="radio" name="_apop_per_page[tax]"
value="default"<?php checked( $per_page_data['_per_page'], 'default' ); ?>>表示設定に従う(<?php echo $default_per_page; ?>
件)</label>
</li>
<li><label>
<input class="per_page_tax" type="radio" name="_apop_per_page[tax]"
value="all"<?php checked( $per_page_data['_per_page'], 'all' ); ?>>全体設定に従う</label>
</li>
<li><label>
<input class="per_page_tax" type="radio" name="_apop_per_page[tax]"
value="-1"<?php checked( $per_page_data['_per_page'], '-1' ); ?>>全件</label>
</li>
<li>
<label><input class="per_page_tax" type="radio" name="_apop_per_page[tax]"
value=""<?php echo $per_page_data['_checked']; ?>>表示数設定
<input class="per_page_tax_input" type="text"
name="_apop_per_page[tax]"
value="<?php echo $per_page_data['_per_page_num']; ?>" required>
</label></li>
</ul>
</dd>
</dl>
</td>
</tr>
<?php endif; ?>
<?php APOP_UI::disp_tax_setting( 'category', 'カテゴリー', '_apop_cat_order' ); ?>
<?php APOP_UI::disp_tax_setting( 'post_tag', 'タグ', '_apop_tag_order' ); ?>
<?php APOP_UI::disp_tax_setting( 'taxonomy', 'カスタム分類', '_apop_tax_order' ); ?>
</table>
<p class="submit"><input type="submit" name="Submit" class="button-primary" value="変更を保存"/>
</form>
+65
View File
@@ -0,0 +1,65 @@
<?php if ( isset( $tax_data, $order_name, $order_tax ) ): ?>
<?php
$default_per_page = get_option( 'posts_per_page' );
$opt_per_page = get_option( '_apop_per_page' );
?>
<dl class="apop_setting_list">
<dt>対象</dt>
<dd>
<ul class="order_setting_list">
<?php foreach ( $tax_data as $tax_datum ): ?>
<?php
$opt_cat = get_option( $order_name );
$check_slug = $opt_cat['target_cat'][ $tax_datum->term_id ] ?? '';
APOP_UI::is_disp_per_page( $disp, $check_slug );
?>
<li>
<div class="select_cat">
<label>
<input type="hidden"
name="<?php echo $order_name; ?>[target_cat][<?php echo $tax_datum->term_id; ?>]"
value="0">
<input class="select_cat_checkbox" type="checkbox"
name="<?php echo $order_name; ?>[target_cat][<?php echo $tax_datum->term_id; ?>]"
<?php checked( $check_slug, 1 ); ?>
value="1">
<?php echo $tax_datum->name; ?>
</label>
</div>
<?php $per_page_data = APOP_UI::create_tax_per_page( $opt_per_page, $order_tax, $tax_datum->term_id ); ?>
<div class="select_per_page">
<ul>
<li>
<label>
<input class="per_page_cat" type="radio"
name="_apop_per_page[<?php echo $order_tax; ?>][<?php echo $tax_datum->term_id; ?>]"
value="default"<?php checked( $per_page_data['_per_page'], 'default' ); ?>>表示設定に従う(<?php echo $default_per_page; ?>
件)</label>
</li>
<li><label>
<input class="per_page_cat" type="radio"
name="_apop_per_page[<?php echo $order_tax; ?>][<?php echo $tax_datum->term_id; ?>]"
value="all"<?php checked( $per_page_data['_per_page'], 'all' ); ?>>全体設定に従う</label>
</li>
<li><label>
<input class="per_page_cat" type="radio"
name="_apop_per_page[<?php echo $order_tax; ?>][<?php echo $tax_datum->term_id; ?>]"
value="-1"<?php checked( $per_page_data['_per_page'], '-1' ); ?>>全件</label>
</li>
<li class="set_number_list">
<label><input class="per_page_cat set_number" type="radio"
name="_apop_per_page[<?php echo $order_tax; ?>][<?php echo $tax_datum->term_id; ?>]"
value=""<?php echo $per_page_data['_checked']; ?>>表示数設定
<input class="per_page_cat_input" type="text"
name="_apop_per_page[<?php echo $order_tax; ?>][<?php echo $tax_datum->term_id; ?>]"
value="<?php echo $per_page_data['_per_page_num']; ?>" required>
</label>
</li>
</ul>
</div>
</li>
<?php endforeach; ?>
</ul>
</dd>
</dl>
<?php endif;
+19 -8
View File
@@ -27,41 +27,52 @@ if ( ! trait_exists( 'APOP_ORDER_SETTING' ) ) {
if ( is_category() ) {
$cat = get_category_by_slug( $query->query_vars['category_name'] );
if ( isset( $cat->term_id ) ) {
$this->set_orderby( $query, $cat->term_id, 'category', 'cat' );
}
}
if ( is_tag() ) {
$tag = get_term_by( 'slug', $query->query_vars['tag'], 'post_tag' );
if ( isset( $tag->term_id ) ) {
$this->set_orderby( $query, $tag->term_id, 'post_tag', 'tag' );
}
}
if ( is_tax() ) {
if ( get_queried_object_id() ) {
$this->set_orderby( $query, get_queried_object_id(), 'tax', 'tax' );
}
}
}
private function set_per_page( $query, $target ) {
private function set_per_page( $query, $target, $id = null ) {
$per_page_option = get_option( '_apop_per_page' );
if ( is_null( $id ) ) {
$per_page_option_data = $per_page_option[ $target ];
} else {
$per_page_target = $target == 'tax' ? 'taxonomy' : $target;
$per_page_option_data = $per_page_option[ $per_page_target ][ $id ];
}
if ( ! isset( $per_page_option[ $target ] ) ) {
if ( ! isset( $per_page_option_data ) ) {
return;
}
if ( $per_page_option[ $target ] == 'default' ) {
if ( $per_page_option_data == 'default' ) {
return;
}
if ( $per_page_option[ $target ] == 'all' ) {
if ( $per_page_option_data == 'all' ) {
$target = 'search';
}
$query->set( 'posts_per_page', $per_page_option[ $target ] );
$query->set( 'posts_per_page', $per_page_option_data );
}
private function set_search_normal_orderby( $query, $type ) {
$apop_order = get_option( '_apop_' . $type . '_order' ) ?? 1;
if ( $apop_order == 2 ) {
//$query->set( 'meta_key', '_apop_post_' . $type );
$query->set( 'meta_query', self::get_all_post_args( '_apop_' . $type . '_order' ) );
$query->set( 'orderby', array( 'meta_value_num' => 'ASC' ) );
$query->set( 'meta_query', self::get_all_post_args( '_apop_post_' . $type ) );
} else {
$apop_order_param = get_option( '_apop_' . $type . '_order_param' );
$sort_param = array( 1 => 'ASC', 2 => 'DESC' );
@@ -89,7 +100,7 @@ if ( ! trait_exists( 'APOP_ORDER_SETTING' ) ) {
//$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 ) );
$this->set_per_page( $query, self::get_per_page_tag( $target ), $id );
} else {
self::set_search_normal_orderby( $query, 'normal' );
}