WP PLUGIN アーカイブページの投稿表示順設定
・検索と通常表示のオプションを追加 ・項目の表示順を修正 ・選択値によって表示/非表示の切り替えやフォームをDisabledにする等修正 ・アンインストーラーを追加
This commit is contained in:
+61
-15
@@ -18,30 +18,26 @@ if ( ! trait_exists( 'APOP_ORDER_SETTING' ) ) {
|
||||
}
|
||||
|
||||
if ( is_home() ) {
|
||||
return;
|
||||
$this->set_search_normal_orderby( $query, 'normal' );
|
||||
}
|
||||
|
||||
if ( is_search() ) {
|
||||
$this->set_per_page( $query, 'search' );
|
||||
$this->set_search_orderby( $query );
|
||||
$this->set_search_normal_orderby( $query, 'normal' );
|
||||
}
|
||||
|
||||
if ( is_category() ) {
|
||||
$cat = get_category_by_slug( $query->query_vars['category_name'] );
|
||||
$this->set_per_page( $query, 'category' );
|
||||
$this->set_orderby( $query, $cat->term_id, 'category', 'cat' );
|
||||
|
||||
}
|
||||
|
||||
if ( is_tag() ) {
|
||||
$tag = get_term_by( 'slug', $query->query_vars['tag'], 'post_tag' );
|
||||
$this->set_per_page( $query, 'tag' );
|
||||
$this->set_orderby( $query, $tag->term_id, 'post_tag', 'tag' );
|
||||
|
||||
}
|
||||
|
||||
if ( is_tax() ) {
|
||||
$this->set_per_page( $query, 'tax' );
|
||||
$this->set_orderby( $query, get_queried_object_id(), 'tax', 'tax' );
|
||||
|
||||
}
|
||||
@@ -55,16 +51,36 @@ if ( ! trait_exists( 'APOP_ORDER_SETTING' ) ) {
|
||||
if ( $per_page_option[ $target ] == 'default' ) {
|
||||
return;
|
||||
}
|
||||
if ( $per_page_option[ $target ] == 'all' ) {
|
||||
$target = 'search';
|
||||
}
|
||||
|
||||
$query->set( 'posts_per_page', $per_page_option[ $target ] );
|
||||
}
|
||||
|
||||
private function set_search_orderby( $query ) {
|
||||
$apop_search_order = get_option( '_apop_search_order' ) ?? 1;
|
||||
if ( $apop_search_order == 2 ) {
|
||||
$query->set( 'meta_key', '_apop_post_search' );
|
||||
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( 'orderby', array( 'meta_value_num' => 'ASC' ) );
|
||||
} else {
|
||||
$apop_order_param = get_option( '_apop_' . $type . '_order_param' );
|
||||
$sort_param = array( 1 => 'ASC', 2 => 'DESC' );
|
||||
if ( ! $apop_order_param ) {
|
||||
return;
|
||||
}
|
||||
foreach ( $apop_order_param as $order_col => $orders ) {
|
||||
if ( $orders['use'] == 1 ) {
|
||||
$orderby[ $order_col ] = $sort_param[ $orders['sort'] ];
|
||||
}
|
||||
}
|
||||
if ( isset( $orderby ) ) {
|
||||
$query->set(
|
||||
'orderby', $orderby
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->set_per_page( $query, 'search' );
|
||||
}
|
||||
|
||||
private function set_orderby( $query, $id, $target, $order_key ) {
|
||||
@@ -73,10 +89,39 @@ if ( ! trait_exists( 'APOP_ORDER_SETTING' ) ) {
|
||||
$sort_meta_key = '_apop_post_' . $target . '_' . $id;
|
||||
$query->set( 'meta_key', $sort_meta_key );
|
||||
$query->set( 'orderby', array( 'meta_value_num' => 'ASC' ) );
|
||||
$target = 'post_tag' ? 'tag' : $target;
|
||||
$this->set_per_page( $query, $target );
|
||||
} else {
|
||||
self::set_search_normal_orderby( $query, 'normal' );
|
||||
}
|
||||
}
|
||||
|
||||
public static function get_orderby( $id, $target, $order_key ): ?array {
|
||||
public static function get_normal_orderby() {
|
||||
$apop_order = get_option( '_apop_normal_order' ) ?? 1;
|
||||
if ( $apop_order == 2 ) {
|
||||
return array(
|
||||
'meta_key' => '_apop_post_normal',
|
||||
'orderby' => array( 'meta_value_num' => 'ASC' ),
|
||||
);
|
||||
} else {
|
||||
$apop_order_param = get_option( '_apop_normal_order_param' );
|
||||
$sort_param = array( 1 => 'ASC', 2 => 'DESC' );
|
||||
foreach ( $apop_order_param as $order_col => $orders ) {
|
||||
if ( $orders['use'] == 1 ) {
|
||||
$orderby[ $order_col ] = $sort_param[ $orders['sort'] ];
|
||||
}
|
||||
}
|
||||
if ( isset( $orderby ) ) {
|
||||
return array(
|
||||
'orderby' => $orderby,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function get_tax_orderby( $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;
|
||||
@@ -85,21 +130,22 @@ if ( ! trait_exists( 'APOP_ORDER_SETTING' ) ) {
|
||||
'meta_key' => $sort_meta_key,
|
||||
'orderby' => array( 'meta_value_num' => 'ASC' )
|
||||
);
|
||||
} else {
|
||||
return self::get_normal_orderby();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function get_per_page( $target ) {
|
||||
$per_page_option = get_option( '_apop_per_page' );
|
||||
if ( ! isset( $per_page_option[ $target ] ) ) {
|
||||
if ( ! isset( $per_page_option ) ) {
|
||||
return;
|
||||
}
|
||||
if ( $per_page_option[ $target ] == 'default' ) {
|
||||
if ( $per_page_option == 'default' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
return array( 'posts_per_page' => $per_page_option[ $target ] );
|
||||
return array( 'posts_per_page' => $per_page_option );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user