Files
POST_ORDER_BY_ARCHIVE/class/class.apop.ui.php
T
nobu 7722f53f10 WP PLUGIN アーカイブ毎に投稿表示順を設定する
・ファイル名、クラス名の変更
・タクソノミーの有効化で、カテゴリー、タグ、カスタム分類のメタキーを分割
・表示用クラスの追加
・readmeの追加等
2021-05-04 16:19:14 +09:00

73 lines
1.7 KiB
PHP

<?php
class APOP_UI {
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_tax_name( $tax_key ): string {
$tax_names = array(
'category' => 'カテゴリー',
'tag_id' => 'タグ',
'custom_tax' => 'カスタム分類',
);
return $tax_names[ $tax_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,
'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 ) {
$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,
];
return get_posts( $args );
}
public static function get_none_sort_post_list( $tax_id, $key, $exclude_posts ) {
$exclude = implode( ',', $exclude_posts );
$args = [
'post_status' => array( 'publish', 'draft' ),
'posts_per_page' => - 1,
$key => $tax_id,
];
if ( ! empty( $exclude ) ) {
$args['exclude'] = $exclude;
}
return get_posts( $args );
}
}