<!-- 質問１　1ページに12件表示する -->
<!-- カスタム投稿スラッグ 「gallery」　　タクソノミー名「gallery-cat」 -->

<div class ="gallery-wrapper">
    <?php
        $term_object = get_queried_object(); // タームオブジェクトを取得
        $term_slug   = $term_object->slug; // タームスラッグ
        $paged = get_query_var('paged') ? get_query_var('paged') : 1;
        $sticky_args = [
            'posts_per_page' => -1,
            'order'          => 'DESC',
            'post_status'    => 'publish',
            'post_type'      => 'gallery',
            'paged' => $paged,
            'tax_query' => array(
                array(
                    'taxonomy' => 'gallery-cat',
                    'field' => 'slug',
                    'terms' => $term_slug,
                ),
            ),
            'post__in'       => get_option('sticky_posts')
        ];

        $args = [
            'posts_per_page' => -1,
            'order'          => 'DESC',
            'post_status'    => 'publish',
            'post_type'      => 'gallery',
            'paged' => $paged,
            'tax_query' => array(
                array(
                    'taxonomy' => 'gallery-cat',
                    'field' => 'slug',
                    'terms' => $term_slug,
                ),
            ),
            'post__not_in'   => get_option('sticky_posts')
        ];
						
        $sticky_query = new WP_Query($sticky_args); // 固定表示の記事を取得
        $the_query    = new WP_Query($args); // 固定表示以外の記事を取得
					
        $new_query = new WP_Query();
        $new_query->posts = array_merge( $sticky_query->posts, $the_query->posts );
        $new_query->post_count = $sticky_query->post_count + $the_query->post_count;
					
    ?>

        <?php 
            if($new_query  -> have_posts()):
               while ( $new_query  -> have_posts() ) : $new_query  -> the_post(); 
        ?>

            //ここにループ投稿

        <?php endwhile; ?>
        <?php endif; ?>
					
</div>

<div class ="page-nation">
    <?php
        if(function_exists('wp_pagenavi')):
            wp_pagenavi(array('query'=>$new_query));
        endif;
    ?>
</div>









<!-- 質問２　タームの背景色を管理画面で変更 -->
<!-- 通常色にはフィールド名「cat-color」、hover時の色には「hover-color」 -->
<div class ="category-item">
    <?php 
        $term_id = $term->term_id;
        $taxonomy   = '◯◯';
        $color = SCF::get('cat-color');
        $hover = SCF::get('hover-color');
        if ( ( $color ) ) {
    ?>
    <a href="<?php echo get_term_link($term_slug, '◯◯');?>" style ="background-color:' . esc_attr( $color ) . ';  onMouseOut="this.style.background='. esc_attr( $color )'; onMouseOver="this.style.background='. esc_attr( $hover )'"?>">
        <p><?php echo $term_name; ?></p>
    </a>
    <?php } ;?>
    </div>
<?php endforeach ;?>
</div>