


<?php 
define('WP_USE_THEMES', false);  
require_once('../../../wp-load.php');

/*
$post_7 = get_post( 87 ); 
$title = $post_7->post_title;


$terms = get_terms('portfolio_tag');

foreach ( $terms as $term ) {
   echo $term->name.'<br />';
   echo "si";
}*/

?>

<!DOCTYPE html>
<html lang="en">
<head>
  <script src="https//code.jquery.com/jquery-1.12.0.min.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.isotope/2.2.2/isotope.pkgd.js"></script>
  

  <meta charset="UTF-8">
  <title>Document</title>
  
  <style>

    #casos{
      width: 100%;
    }
    
    .rowCasos{
      width: 100%;
    }

    .columnCasos{
      float: left;
      width: 25%;
      padding: 1em 0;
    }

    .bolder{
      font-weight: bold;
    }

  </style>
  <script src="http://code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>

</head>



<body>
  
<h2>Casos Destacados</h2>

<div class="grillaDestacados">
<?php


    $the_query = new WP_Query( array(

        'post_type'      => 'portfolio',
        'nopaging'        => true,
        'orderby'                => 'title',
      
    ) );

    if ( $the_query->have_posts() ) {
      
      $counter = 0;
	  

      while (  $the_query->have_posts() ) : $the_query->the_post(); 
        
        $image = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), $image_size );



        $url = get_the_permalink();

        if($counter<22){

            $return .= '<article class="pagina1 destacados portfolio-item '. $class . '" data-id="' . get_the_ID() . '">';

        } elseif($counter >22 && $counter < 44){

          $return .= '<article class="pagina2 destacados portfolio-item '. $class . '" data-id="' . get_the_ID() . '">';

        } elseif($counter >44 && $counter < 66){

          $return .= '<article class="pagina3 destacados portfolio-item '. $class . '" data-id="' . get_the_ID() . '">';

        }

        


        $return .= '<a href="' . $url . '">';
          $return .= '<img src="' . $image[0] . '" alt="' . get_the_title() . '">';
          $return .= '<div class="hover">';
            $return .= '<div class="hover-content">';
              $return .= '<h5>' . get_the_title() . '</h5>';
              if( $below_title != 'none' ) {
                $return .= '<span>' . $below_title_content . '</span>';
              }
            $return .= '</div>';
          $return .= '</div>';
        $return .= '</a>';
          $return .= '</article>';


          $counter = $counter +1;

        endwhile;
 
          wp_reset_postdata();

    }

    
          echo '<div class="portfolio portfolio-masonry-spacing portfolio-hover-style-2">' . $return . '</div>';


  ?>


</div>

<?php


          $divisor = $counter / 22;

          for($i=0; $i<$divisor; $i++){

            ?>

            <a href="#" data-page=<?php echo $i+1 ?> > Page  </a>


            <?php

          }

?>

<script>
  
   var grid = jQuery(".grillaDestacados");
    
    grid.isotope({
      itemSelector: ".destacados",
      layoutMode: "fitRows"
    });


  



alert("hola");

</script>

<h2>Proyectos generales</h2>


<?php

$anoAr = array(); 
$actividadAr = array(); 
$paisAr = array(); 

$exporter;
$exporter = '<table id="rowsCasos" style="width:100%" >
   <tr class="bolder">
    <td>Cliente</td> 
    <td>Actividad</td>
    <td>País</td>
    <td>Año</td>
  </tr>';


$the_query = new WP_Query( array(

    'post_type'              => array( 'portfolio' ),
    'nopaging'               => true,
    'paged'                  => '10',
    'posts_per_page'         => '10',
    'orderby'                => 'title',
  

  ) );

/*  'meta_key'               => 'actividad',
    'meta_value'             => 'Agropecuaria'*/

 if ( $the_query->have_posts() ) {

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

           $selected = get_field('link');

             $exporter .=  '<tr>';

             if( is_array($selected) && in_array('si', $selected) ) {

              $exporter .=  '<td>';
              $title = get_the_title();
              $exporter .=  $title;
              $exporter .=  '</td>';

             }else{

               $exporter .=  '<td>';
               $exporter .=  '<a target="_blank" href="'.get_the_permalink().'">';
               $title = get_the_title();
               $exporter .=  $title;
             
               $exporter .=  '</a>';
               $exporter .=  '</td>';

             }



              $idPost =  $post->ID;
            
              $exporter .=  '<td>';
                $actividad = get_field( "actividad" );
                $exporter .=  $actividad;

                if  ($actividad!= ""){

                if (in_array($actividad, $actividadAr)) {
                
                    //echo "Existe esta variable".$ano;
                
                }else{

                 //echo "no existe";
                  array_push($actividadAr, $actividad);
                }

                }else{
                  //echo "hay un espacio";
                }

              $exporter .=  '</td>';
              $exporter .=  '<td>';
                
                $pais = get_field( "pais" );
                $exporter .=  $pais;

                if  ($pais!= ""){

                if (in_array($pais, $paisAr)) {
                
                    //echo "Existe esta variable".$ano;
                
                }else{

                 //echo "no existe";
                  array_push($paisAr, $pais);
                }

                }else{
                  //echo "hay un espacio";
                }

              $exporter .=  '</td>';
              $exporter .=  '<td>';

                $ano = get_field( "ano" );
                $exporter .=  $ano;
               
                if  ($ano!= ""){
                
                  if (in_array($ano, $anoAr)) {
                      //echo "Existe esta variable".$ano;
                  
                  }else{

                   //echo "no existe";
                    array_push($anoAr, $ano);
                  }

                }else{
                  //echo "hay un espacio";
                }

              $exporter .=  '</td>';
        
          $exporter .=  '<tr>';
   
    endwhile;
 
    wp_reset_postdata(); 

     $exporter .=  '</table>';

}

echo $exporter;

//?>









</body>
</html>
