<?php
/*
Template Name: research Page Template
*/
get_header();
?>
<div id="contents">
  <div id="main_content">

    <div class="title_container">
    <h1>研究報告</h1>
      <h2>Research</h2>
    </div>

    <article class="common-page-main" id="main">

      <div class="section_wrapper">
      <div class="common_list_container">
        <?php
          if (function_exists('custom_breadcrumb')) {
            custom_breadcrumb();
          }
        ?>
<!--           <p>プロトコル・倫理審査・学会発表別で研究データを確認できます。</p> -->
          <div class="tab_menu postList_tab" data-width-pc="25" data-width-sp="50">
            <ul id="js-tab" class="list-tab tab_List">

              <li class="active tab_List_item"><button class="tabList_button active" role="tab" aria-controls="post_list_tab_1" aria-selected="true" data-taxonomy-slug="ethics">進行中の研究</button></li>
              <li class="tab_List_item"><button class="tabList_button" role="tab" aria-controls="post_list_tab_2" aria-selected="false" data-taxonomy-slug="presentation">学会発表後の研究</button></li>
            </ul>
          </div>
          <div class="section_container">
            <section class="sectionLv04">
              <div class="wrap-tab-content">
                <?php
                $tabs = array(
                  array(
                    'slug' => 'ethics',
                    'taxonomy_slug' => 'program_cate',
                  ),
                  array(
                    'slug' => 'presentation',
                    'taxonomy_slug' => 'program_cate',
                  ),
                );

                foreach ($tabs as $index => $tab) {
                  $args = array(
                    'post_type' => 'program',
                    'posts_per_page' => -1,
                    'tax_query' => array(
                      array(
                        'taxonomy' => $tab['taxonomy_slug'],
                        'field' => 'slug',
                        'terms' => $tab['slug'],
                      ),
                    ),
                  );
                  $query = new WP_Query($args);

                  if ($query->have_posts()) {
                    $active_class = ($index === 0) ? ' active' : ''; // 最初のタブに active クラスを追加 ?>
                    <ul id="post_list_<?php echo $tab['slug']; ?>" class="tab-content<?php echo $active_class; ?>">
                      <?php while ($query->have_posts()) {
                        $query->the_post();
                        $categories = get_the_terms(get_the_ID(), 'program_cate');
                        $category_classes = array();

                        if ($categories) {
                          foreach ($categories as $category) {
                            $category_classes[] = $category->slug;
                          }
                        } ?>

                        <li class="program_post <?php echo implode(' ', $category_classes); ?>">
                          <div class="post-date"><?php echo get_the_date('Y.n.j'); ?></div>
                          <div>
                            <h4><?php $value = get_field('field_64b0d5b4fccca'); if ($value) echo $value; ?></h4>
                            <div>
                              <?php $value = get_field('field_64b0d7f10e5e5'); if ($value) echo $value;
                              $value = get_field('field_64b0d7d534404'); if ($value) echo $value; ?>
                            </div>
                            <span class="categories">
                              <?php foreach ($categories as $category) { ?>
                                <a class="<?php echo $category->slug; ?>" href="<?php echo esc_url(get_category_link($category->term_id)); ?>" rel="category tag"><?php echo $category->name; ?></a>
                              <?php } ?>
                            </span>
                            <h3 class="program_title"><?php echo get_the_title(); ?></h3>
                            <p><?php $value = get_field('field_64b0e0316def0'); if ($value) echo $value; ?></p>
                          </div>
                        </li>
                      <?php } ?>
                    </ul>
                  <?php }

                  wp_reset_postdata();
                }
                ?>
              </div>
              <div class="btn_container">
                <!-- <a class="btn_primary" href="<?php echo get_permalink(get_page_by_path('notice')); ?>">一覧を見る</a> -->
              </div>
            </section>
          </div>
        </div>
      </div>

    </article>
  </div>
</div>
<?php
get_footer();
?>