<?php
/**
 * Template Name: Presentations
 *
 * @package gralbcn
 */

get_header(); ?>
<div class="container grid">




			
	


<div class="presentations-page">
  <h2>—Conference Presentations & Invited Talks</h2>

  <?php
  // Obtener todos los posts y agruparlos por año
  $presentations = new WP_Query(array(
    'post_type' => 'post',
    'posts_per_page' => -1,
    'category_name' => 'presentations',
    'orderby' => 'meta_value',
    'meta_key' => 'full_date',
    'order' => 'DESC'
  ));

  $years = array();
  if ($presentations->have_posts()) :
    while ($presentations->have_posts()) : $presentations->the_post();
      $full_date = get_field('full_date');
      $year = '';
      if ($full_date) {
        $year = date('Y', strtotime($full_date));
      } else {
        $year = 'No date';
      }

      $years[$year][] = array(
        'authors' => get_field('authors'),
        'title' => get_the_title(),
        'extra_info' => get_field('extra_info'),
        'full_date' => $full_date,
        'location' => get_field('location')
      );
    endwhile;
    wp_reset_postdata();
  endif;

  // Ordenar años descendentemente
  krsort($years);

  ?>

  <!-- Menú de años -->
  <div class="years-menu">
    <?php
    $first = true;
    foreach ($years as $y => $items) {
      echo '<span class="year-item' . ($first ? ' active' : '') . '" data-year="' . esc_attr($y) . '">' . esc_html($y) . '</span> ';
      $first = false;
    }
    ?>
  </div>

  <!-- Contenido de cada año -->
  <div class="years-content">
    <?php
    $first = true;
    foreach ($years as $y => $items) {
      echo '<div class="year-block" data-year="' . esc_attr($y) . '"' . ($first ? '' : ' style="display:none;"') . '>';
      foreach ($items as $p) {
        $year_in_paren = ($p['full_date']) ? date('Y', strtotime($p['full_date'])) : '';
        echo '<p>';
        echo esc_html($p['authors']) . ' (' . esc_html($year_in_paren) . '). ';
        echo '<span class="blue">' . esc_html($p['title']) . '</span>. ';
        echo esc_html($p['extra_info']) . '. ';
        echo esc_html($p['full_date']) . ', ' . esc_html($p['location']);
        echo '</p>';
      }
      echo '</div>';
      $first = false;
    }
    ?>
  </div>
</div>









</div> <!-- end container -->








<?php get_footer(); ?>