<?php

/**

 * Template Name: Blog Template

 */

get_header(); ?>

<?php $banner_image = get_field('banner_image');?>

<div class="banner-page-blog fusion-fullwidth" style="background-image:url('<?=$banner_image['url'];?>')">
    <h1 style="text-align:center;"><?=the_title();?></h1>
</div>

<!--Featured Blogs-->
<div class="featured-blog-holder">
    <div class="container mt-60p featured-container">
        <div class="blog-list-row">
            <?php
            $posts = get_field('featured_blog');
            if( $posts ): ?> 
                    <?php foreach( $posts as $post):  ?>
                        <?php setup_postdata($post);
                            $post_id       = $post->ID;
                            $post_title    = $post->post_title;
                            $post_link     = get_permalink($post_id);
                            $position  = get_field('position', $post_id);
                            $name  = get_field('name', $post_id);
                            $image1  = get_field('image', $post_id);
                            $arraylist = $post_id ;
                            $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'single-post-thumbnail' ); 
                        ?>
                        <div class="cols col-featured-card card card-featured">
                            <div class="featured-image" style="background-image:url('<?=$image[0];?>);">
                                <!-- <?php if (has_post_thumbnail($post_id)){
                                    $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'single-post-thumbnail' ); 
                                    echo '<img class="img-full" src="'. $image[0] .'" alt="'. get_the_title() .'" />';
                                    } else if ( catch_that_image() ) {
                                        echo catch_that_image();
                                    } else {
                                        echo '<img class="img-full" src="/wp-content/uploads/2022/07/press-release-770x367px-green.webp" alt="'. get_the_title() .'" />';
                                    } 
                                ?> -->
                            </div>
                        <div class="card-body">
                                <div class="blog-date">
                                    <p class="date-txt"><?php echo get_the_date('F j, Y'); ?></p>
                                </div>
                            <h2 class="card-title"><?php the_title(); ?></h2>
                            <p class="card-text"><?php the_field('short_description')?></p>
                            <div class="bottom-content">
                                <div class="imageholder">
                                        <img src="<?=$image1['url'];?>" alt="<?=$image1['url'];?>">
                                </div>
                                <div class="desc">
                                    <h4><?=$name;?></h4>
                                    <span><?= $position;?></span>
                                </div>
                            </div>
                            <div class="card-cta-featured">
                                <a href="<?php the_permalink()?>" class="fusion-button button-flat fusion-button-default-size button-default button-1 fusion-button-default-span fusion-button-default-type">READ MORE</a>
                            </div>
                        </div>
                        
                    </div>
                    <?php endforeach; ?>      
                <?php wp_reset_postdata();
            endif; 

        ?>
        </div>
    </div>
</div>

<div class="blog-list-holder fusion-fullwidth" style="background-color:#F6F6F6;">

<div class="container" style="margin-top: 10px;">
     <h3 class="blog-list-title text-center">View More Blogs</h3>
    <div class="blog-list-row">
        <?php 
            $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
            $args = array(
                'post_type' => 'post',
                'post__not_in' => $posts, 
                // 'category_name' => 'Blogs', 
                'posts_per_page' => 6,
                'paged' => $paged
            );
            //query_posts( $args );

            $wp_query = new WP_Query( $args );
             // echo "<pre>",print_r($wp_query),"</pre>";

            //$posts= get_posts( $args ); ?> 

            <?php if ( $wp_query->have_posts() ) : ?> 

            <?php while ( $wp_query->have_posts() ) : $wp_query->the_post();

            $post       = $wp_query->post;
            $post_id    = $post->ID;
            $post_title = $post->post_title; 
            $position  = get_field('position', $post_id);
                            $name  = get_field('name', $post_id);
                            $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'single-post-thumbnail' ); 
                            $image1  = get_field('image', $post_id);
            ?>
        <!--<div class="cols col-md-4">-->
            <div class="item">
            <div class="featured-image" style="background-image:url('<?=$image[0];?>);">
                    <!-- <?php 
                        $post_id       = $post->ID; ?>
                        <?php if (has_post_thumbnail($post_id)){
                            $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'single-post-thumbnail' ); 
                            echo '<img class="img-full" src="'. $image[0] .'" alt="'. get_the_title() .'" />';
                            } else if ( catch_that_image() ) {
                                echo catch_that_image();
                            } else {
                                echo '<img class="img-full" src="/wp-content/uploads/2022/07/press-release-770x367px-green.webp" alt="'. get_the_title() .'" />';
                            } 
                        ?> -->
                    </div>
                <div class="card-body">
                    <div class="blog-date">
                        <p class="date-txt"><?php echo get_the_date('F j, Y'); ?></p>
                    </div>
                <h5 class="card-title"> <a href="<?php the_permalink()?>"> <?php the_title(); ?> </a> </h5>
                <p class="card-text"><?php the_field('short_description')?></p>
                <div class="bottom-content">
                <div class="imageholder">
                                        <img src="<?=$image1['url'];?>" alt="<?=$image1['url'];?>">
                                </div>
                                <div class="desc">
                                    <h4><?=$name;?></h4>
                                    <span><?= $position;?></span>
                                </div>
                            </div>
              </div>
            </div>
        <!--</div>-->
        
        <?php endwhile;
                    endif; ?>
                     <?php wp_reset_postdata(); ?>
        
        
       
    </div>
    <div class="pagination mt-60p">
                        <div class="pagination-items">
					<?php
					global $wp_query; //optional

					$big = 999999999; // need an unlikely integer

					echo paginate_links( array(
						'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
						'format'  => '?paged=%#%',
						'current' => max( 1, get_query_var('paged') ),
						'total'   => $wp_query->max_num_pages
					) );
					?>
					 <!-- 		option 1 end			 -->
                     </div> 
                    </div>
                    <?php// echo bittersweet_pagination(); ?>
</div>

</div>


<?php get_footer(); ?>