<?php
/*
Plugin Name: Herminette-shortcode
Description: Plugin fournissant le shortcode nos-realisations
Author: Apeonmars
Version: 1.0.0
*/

function shortcode_realisations(){
    ?>
    <div class="grid">

      <?php


      $the_query = new WP_Query( array('posts_per_page'=>18,
      'post_type'=>'realisation',
      'post_status' => 'publish',
      'orderby' => 'date',
      'order' => 'DESC',
      'paged' => get_query_var('paged') ? get_query_var('paged') : 1)
    );


    $index= $getPost->current_post+1;



    while ($the_query -> have_posts()) : $the_query -> the_post(); $count++;


    $index = $wp_query->current_post ++;


    echo '<div class="grid-item">';
    echo'<a href="';
    the_permalink();
    echo '">';



    if($count%2 == 0){

      // article impair ( square )

      echo'<div class="container-realisation">';
      echo'<div class="image-realisation">';
      the_post_thumbnail('realisation-square');
      echo'</div>';

      echo'<div class="description-realisation">';
      echo"<h1>";
      the_title();
      echo "</h1>";
      echo'<p class="localite">';
      global $post;
      $meta = get_post_meta($post->ID,'_my_meta_value_key', true);
      echo $meta;
      echo"</p>";
      echo '<div class="extrait-realisation">';
      //the_excerpt();
      echo'<p>';
      echo wpex_get_excerpt_square();
      //echo wpex_get_excerpt();
      echo'</p>';
      echo'</div>';


      echo'</div>';
      echo'</div>';

    }else{

      // article pair

      echo'<div class="container-realisation">';
      echo'<div class="image-realisation">';
      the_post_thumbnail('realisation-rectangle');
      echo'</div>';

      echo'<div class="description-realisation">';

      echo"<h1>";
      the_title();
      echo "</h1>";


      echo'<p class="localite">';
      global $post;
      $meta = get_post_meta($post->ID,'_my_meta_value_key', true);
      echo $meta;
      echo"</p>";
      echo '<div class="extrait-realisation">';
      //the_excerpt();
      echo'<p>';
      echo wpex_get_excerpt();
      echo'</p>';
      echo'</div>';
      echo '</div>';

      echo'</div>';

    }




    ////



    ////
    echo "</a>";
    echo'</div>';

  endwhile;




  wp_reset_postdata();

  ?>
  </div> <!-- Grid -->

  <?php
  // pagination links
  echo'<div class="container">';
  echo'<div class="custom-pagination">';
  $big = 999999999; // need an unlikely integer
  echo paginate_links( array(
    'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
    'format' => '?paged=%#%',
    'current' => max( 1, get_query_var('paged') ),
    'total' => $the_query->max_num_pages
  ) );
  echo "</div></div>";





}

add_shortcode('nos-realisations', 'shortcode_realisations');
