<?php
/*
Template Name: Work2
*/
?>
<?php get_header();?>  
    <div class="content-wrapper">
    	<div class="container">
    		<?php
    		setup_postdata($post);	
    		 $terms = get_terms('works_category');
    		if($terms):?>
    		   <ul id="filters" class="pull-right">					  
    				  <li><a href="#" data-filter="*"><p class="post-categoty"><?php echo _e('all','hybrid_lang');?></p></a></li>
    				<?php foreach ( $terms as $term ) :?>
    					<li><a href="#" data-filter=".<?php echo str_replace(' ','_',$term->name);?>"><p class="post-categoty"><?php echo $term->name;?></p></a></li>
    				<?php endforeach;?>
    			</ul>
    		<?php endif; ?>
            <h3><?php the_field("work_title"); ?></h3>
    <div class="row">
        <div id="portfolio2-items">
            <div class="span0"></div>
    	</div>
    </div>
        <script>
            var items1 = [];			
            <?php             
				/*$load_galleries = 4;//get_field('load_more'); //The number that the button Load More should load!
                if($load_galleries <= 0) $load_galleries = 4;

                $post_per_page  = 4;//get_field('works_on_page');//The number that will display galleries on page load!
                if($post_per_page <= 0) $post_per_page = 12;
				*/			
				$post_num  = get_field('works_on_page');//get_field("post_number","options");
				 if($post_num <= 0) $post_num = 4;
				$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
            ?>			
            var load_galleries = "<?php echo $post_num; ?>";
            var post_per_page = "<?php echo $paged; ?>";

                <?php $args1 = array(
                    'post_type' => 'work_post',
                    'posts_per_page' => $post_num ,
					'paged'     => $paged
                );
                $the_query = new WP_Query($args1);
				$countpost = wp_count_posts('work_post');
				?>
				var maxNumPages = "<?php  echo $the_query->max_num_pages;?>";
				<?php
			   while ( $the_query->have_posts() ):
                        $the_query->the_post();

                    $current_categories = get_the_terms(get_the_ID(),'works_category');
                    $className = '';
                    if( $current_categories)
                    {
                        foreach($current_categories as $cat)
                        {
                            $className = $className.' '.str_replace(' ','_',$cat->name);
                        }
                    }?>

                      items1.push("<a href=\"<?php the_permalink();?>\"><div class=\"portfolio-item span6 <?php echo $className; ?> \" >"+
                            "<?php if(has_post_thumbnail()):?>"+
                            "<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'home2-featured',false); ?>"+
                            "<div class=\"image-container\"><img src=\"<?php echo $image[0]; ?>\" alt=\"T 2\"/>"+
							"<div class=\"image-hover\"></div></div>"+
                            "<?php endif; ?>"+
                            "<h4><?php the_title();?></h4>"+
                            "<p class=\"post-categoty capitalize\"></p>"+
							"</div></a>"
                        );
            <?php endwhile; ?>
        </script>	
		<?php if(	$countpost->publish>$post_num) :?>
        <div class="row">
        	 <div class="span12">
        		<p id="load-more-works2" class="load-more"><?php echo _e('LOAD','hybrid_lang');?> <br> <?php echo _e('MORE','hybrid_lang');?><br>...</p>	
        	 </div>
        </div>
		<?php endif; ?>
   </div><!--container-->
</div><!--.content-wrapper-->  
<?php wp_reset_postdata(); ?>	  
<?php get_footer();?>