<?php $__env->startSection('content'); ?>

<?php
  $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

  $wp_query = new WP_Query( array(
    'post_status' => 'publish',
    'post_type' => array('works', 'works_others'), //カスタム投稿タイプ名
    'taxonomy' => 'works_cat',
    'paged' => $paged,
    // 'posts_per_page' => 15,
    'posts_per_page' => 6,
    'orderby'     => 'date',
    'order' => 'DESC'
  ) );

  $post_types = array( 'works', 'works_others' );
  foreach ( $post_types as $post_type ) {
    $all_post_count += wp_count_posts( $post_type )->publish;
  }
?>

<?php
  global $wp_rewrite;
  $paginate_base = get_pagenum_link(1);
  if(strpos($paginate_base, '?') || ! $wp_rewrite->using_permalinks()){
    $paginate_format = '';
    $paginate_base = add_query_arg('paged','%#%');
  }else{
    $paginate_format = (substr($paginate_base,-1,1) == '/' ? '' : '/') .
    user_trailingslashit('page/%#%/','paged');
    $paginate_base .= '%_%';
  }

  $current_pgae = get_query_var( 'paged' );
  $current_pgae = $current_pgae == 0 ? '1' : $current_pgae;
  $max_pages = $wp_query->max_num_pages;
 ?>



<div class="works-header">
  <div class="d-flex align-items-center justify-content-between mb-5 pb-2">
    <div>
      <h1 class="en">Works</h1>
      <img class="works-logo" src="<?= App\asset_path('images/works-logo.png'); ?>">
    </div>

    <div class="d-flex">
      <a class="btn-black" href="#">お問い合わせ</a>
      <a class="btn-white ml-3" href="#">資料ダウンロード <svg xmlns="http://www.w3.org/2000/svg" width="9.5" height="9.5" viewBox="0 0 9.5 9.5"><g transform="translate(-4 -4)"><path d="M11.273,17.563H6.227A2.229,2.229,0,0,1,4,15.336v-.891a.445.445,0,0,1,.891,0v.891a1.338,1.338,0,0,0,1.336,1.336h5.047a1.338,1.338,0,0,0,1.336-1.336v-.891a.445.445,0,0,1,.891,0v.891A2.23,2.23,0,0,1,11.273,17.563Z" transform="translate(0 -4.063)" fill="#122a37"/><path d="M11.7,10.531a.445.445,0,0,1-.445-.445V4.445a.445.445,0,0,1,.891,0v5.641A.445.445,0,0,1,11.7,10.531Z" transform="translate(-2.945)" fill="#122a37"/><path d="M10.375,12.969a.448.448,0,0,1-.327-.142l-1.93-2.079a.445.445,0,0,1,.653-.606l1.6,1.726,1.6-1.726a.445.445,0,1,1,.653.606L10.7,12.827A.448.448,0,0,1,10.375,12.969Z" transform="translate(-1.625 -2.438)" fill="#122a37"/></g></svg></a>
    </div>
  </div>

  <div class="d-flex align-items-center justify-content-between mb-5">
    <div class="works-header-info">
      <h2 class="d-inline-block"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="10" height="10" viewBox="0 0 10 10">
      <defs>
        <linearGradient id="linear-gradient" x1="0.5" x2="0.5" y2="1" gradientUnits="objectBoundingBox">
          <stop offset="0" stop-color="#b760f4"/>
          <stop offset="1" stop-color="#5f2ab3"/>
        </linearGradient>
      </defs>
      <circle cx="5" cy="5" r="5" fill="url(#linear-gradient)"/>
      </svg>&nbsp;&nbsp;最新の実績</h2>
      <p class="d-inline-block ml-3">掲載実績数 : <?php echo $all_post_count; ?></p>
    </div>

    <div class="pagination">
      <ul class="d-flex">
        <li><svg class="mb-1" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24"><path d="M16.67 0l2.83 2.829-9.339 9.175 9.339 9.167-2.83 2.829-12.17-11.996z"/></svg><?php previous_posts_link('<svg class="mb-1" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24"><path d="M16.67 0l2.83 2.829-9.339 9.175 9.339 9.167-2.83 2.829-12.17-11.996z"/></svg>') ?></li>
        <li><span class="current-page"><?php echo $current_pgae; ?></span></li>
        <li><svg class="mb-1" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24"><path d="M5 3l3.057-3 11.943 12-11.943 12-3.057-3 9-9z"/></svg><?php next_posts_link('<svg class="mb-1" xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24"><path d="M5 3l3.057-3 11.943 12-11.943 12-3.057-3 9-9z"/></svg>', $max_pages) ?></li>
        <li><span class="max-pages">&frasl;&nbsp;&nbsp;<?php echo $max_pages; ?></span></li>
      </ul>
    </div>

  </div>
</div>

<div class="works-list-wrap mb-5">
  <ul class="works-list d-flex flex-wrap">

<?php
  if( $wp_query->have_posts() ): while( $wp_query->have_posts() ) : $wp_query->the_post();
?>
    <li>
      <?php $url = get_field('works_url'); if($url): ?>
        <a href="<?php echo $url; ?>" target="_blank">
      <?php else: ?>
        <a href="<?php the_permalink(); ?>">
      <?php endif; ?>
        <div class="works-list-image">
          <?php if( has_post_thumbnail() ): ?>
            <img data-src="<?php the_post_thumbnail_url(); ?>" class="lazyload">
          <?php else: ?>
            <img data-src="<?= App\asset_path('images/service/service_d2c.jpg'); ?>" class="lazyload">
          <?php endif; ?>
        </div>
        <div class="works-list-text">
        <?php $name = get_field('works_client_name'); if($name): ?>
          <p class="client-name"><?php echo $name; ?></p>
        <?php endif; ?>
        <h3><?php the_title(); ?></h3>
        <div>
          <?php echo $post->post_title; ?>
<?php the_ID(); ?>
<?php
    if ($terms = get_the_terms($post->ID, 'works_cat')) {
        foreach ( $terms as $term ) {
            echo ('<span>') ;
            echo esc_html($term->name)  ;
            echo ('</span>') ;
        }
    }
?>

          <!-- <span class="cat-agent">aaa</span> -->
        </div>
      </div>
      </a>
    </li>
<?php endwhile; endif; wp_reset_postdata(); ?>
  </ul>
</div>

<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>