<?php
    $fixheight_title       = new_blogbell_get_option( 'fixheight_title' );
    $fixheight_subtitle       = new_blogbell_get_option( 'fixheight_subtitle' );
    $fixheight_right_content_type     = new_blogbell_get_option( 'fixheight_right_content_type' );
    $enable_right_category     = new_blogbell_get_option( 'fixheight_right_category_enable' );
    $enable_right_content     = new_blogbell_get_option( 'fixheight_right_content_enable' );
    $enable_right_author     = new_blogbell_get_option( 'fixheight_right_author_enable' );
    $enable_right_posted_on     = new_blogbell_get_option( 'fixheight_right_posted_on_enable' );
    $fixheight_content_type     = new_blogbell_get_option( 'fixheight_content_type' );
    $enable_category     = new_blogbell_get_option( 'fixheight_category_enable' );
    $enable_content     = new_blogbell_get_option( 'fixheight_content_enable' );
    $enable_author     = new_blogbell_get_option( 'fixheight_author_enable' );
    $enable_posted_on     = new_blogbell_get_option( 'fixheight_posted_on_enable' );
    $number_of_fixheight_items  = new_blogbell_get_option( 'number_of_fixheight_items' );
    $fixheight_category = new_blogbell_get_option( 'fixheight_category' );
    $header_font_size = new_blogbell_get_option( 'fixheight_font_size');
    $number_of_fixheight_column = new_blogbell_get_option('number_of_fixheight_column');
    $content_align = new_blogbell_get_option('fixheight_content_align');
    $excerpt_length =new_blogbell_get_option( 'fixheight_excerpt_length');
    $excerpt_right_length =new_blogbell_get_option( 'fixheight_right_excerpt_length');
    $fixheight_post_count =new_blogbell_get_option( 'fixheight_post_count_enable');
    $homepage_layout_options = new_blogbell_get_option('homepage_design_layout_options');

    $see_more_txt     = new_blogbell_get_option( 'fixheight_see_all_txt' );
    $see_more_url     = new_blogbell_get_option( 'fixheight_see_all_url' );

    for( $i=1; $i<=$number_of_fixheight_items; $i++ ) :
        $fixheight_page_posts[] = absint(new_blogbell_get_option( 'fixheight_page_'.$i ) );
        $fixheight_post_posts[] = absint(new_blogbell_get_option( 'fixheight_post_'.$i ) );
    endfor;

?> 
<style>
    <?php if ($header_font_size != 0): ?>
        #fixheight .section-title{
            font-size:<?php echo esc_attr($header_font_size); ?>px;
        }
    <?php endif ?>
</style>
<?php if(!empty($fixheight_title) ):?>
    <div class="section-header">
        <?php if (!empty($fixheight_title)): ?>
            <h2 class="section-title"><?php echo esc_html($fixheight_title);?></h2>
            <?php if ($homepage_layout_options=='home-main' && !empty($see_more_txt) && !empty($see_more_url)): ?>
                <a class="see-all" href="<?php echo esc_url($see_more_url) ?>" data-text="<?php echo esc_html($see_more_txt); ?>"><?php echo esc_html($see_more_txt); ?></a>
            <?php endif ?>
        <?php endif; ?>
    </div>       
<?php endif;?>
<div class="fixheight-content-wrapper">
    <div id="fixheight-right" class="fixheight-right-wrapper clear ">
        <?php 
            $fixheight_right_id = new_blogbell_get_option( 'fixheight_right_post' );
            $args = array (
                'post_type'     => 'post',
                'posts_per_page' => 1,
                'p' => $fixheight_right_id,
                'ignore_sticky_posts' => true, 
            );  
            $the_query = new WP_Query( $args );

            // The Loop
            while ( $the_query->have_posts() ) : $the_query->the_post();
            ?>
                <article class="<?php echo has_post_thumbnail() ? 'has-post-thumbnail' : 'no-post-thumbnail' ; ?>">
                    <div class="fixheight-right-item-wrapper">
                        <?php if (has_post_thumbnail()) : ?>
                            <div class="post-featured-image">
                                <div class="featured-image" style="background-image: url('<?php the_post_thumbnail_url();?>');">
                                    <a href="<?php the_permalink();?>" class="post-thumbnail-link"></a>
                                    <?php $homepage_video_url = get_post_meta( get_the_ID(), 'new-blogbell-video-url', true ); ?>
                                    <?php if (!empty($homepage_video_url)){ ?>
                                       <div class="play-icon">
                                            <a class="video-popup" href="<?php echo esc_url( $homepage_video_url ); ?>"><i class="fa fa-play"></i></a>
                                        </div><!-- .icon-play -->
                                    <?php } else{ ?>
                                        <?php $video_link  = new_blogbell_get_option( 'fixheight_video_link'); ?>
                                        <?php if ( ! empty( $video_link ) ) { ?>
                                            <div class="play-icon">
                                                <a class="video-popup" href="<?php echo esc_url( $video_link ); ?>"><i class="fa fa-play"></i></a>
                                            </div><!-- .icon-play -->
                                        <?php } } ?> 
                                    <?php if ($homepage_layout_options=='home-main'): ?>
                                        <div class="entry-container">
                                            <div class="header-part">
                                                <?php if ( ($fixheight_right_content_type !== 'fixheight_right_page') && ($enable_right_category==true)) : ?>
                                                    <div class="entry-meta">
                                                        <?php new_blogbell_entry_meta(); ?>
                                                    </div><!-- .entry-meta -->
                                                <?php endif; ?>
                                                <header class="entry-header">
                                                    <h2 class="entry-title"><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>
                                                </header>
                                            </div>
                                            <?php if ($enable_right_posted_on==true) : ?>
                                                <div class="right-entry-meta">
                                                    <?php 
                                                        if (($enable_right_posted_on==true)) {
                                                            new_blogbell_posted_on();
                                                        } 
                                                     ?>
                                                </div><!-- .entry-meta -->
                                            <?php endif; ?> 
                                        </div><!-- .entry-container -->
                                    <?php endif ?>
                                </div><!-- .featured-image -->
                            </div>
                        <?php endif; ?>
                        <?php if ($homepage_layout_options !='home-main'): ?>
                            <div class="entry-container <?php echo esc_attr($content_align); ?>">
                                <?php if (($enable_right_category==true)) : ?>
                                    <div class="entry-meta">
                                        <?php new_blogbell_entry_meta(); ?>
                                    </div><!-- .entry-meta -->
                                <?php endif; ?>
                                <header class="entry-header">
                                    <h2 class="entry-title"><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>
                                </header>
                                <?php if ((($enable_right_posted_on==true) || ($enable_right_author==true))) : ?>
                                    <div class="entry-meta">
                                        <?php 
                                            if (($enable_right_posted_on==true)) {
                                                new_blogbell_posted_on();
                                            } 
                                            if (($enable_right_author==true)) {
                                                new_blogbell_author();
                                            }
                                         ?>
                                    </div><!-- .entry-meta -->
                                <?php endif; ?>
                                <?php if (($enable_right_content==true)) : ?>
                                    <div class="entry-content">
                                        <?php
                                            $excerpt = new_blogbell_the_excerpt( $excerpt_right_length );
                                            echo wp_kses_post( wpautop( $excerpt ) );
                
                                        ?>
                                    </div><!-- .entry-content -->
                                <?php endif; ?>  
                            </div><!-- .entry-container -->
                        <?php endif; ?>
                    </div>
                </article>
            <?php endwhile; ?>
    </div>
    <div class="fixheight-wrapper clear col-2">
        <?php
            $args = array (

            'posts_per_page' =>absint( $number_of_fixheight_items ),              
            'post_type' => 'post',
            'post_status' => 'publish',
            'paged' => 1,
            'ignore_sticky_posts' => true, 
            );
            if ( absint( $fixheight_category ) > 0 ) {
                $args['cat'] = absint( $fixheight_category );
            }
            $loop = new WP_Query($args);                        
            if ( $loop->have_posts() ) :
                $i=0;  
                while ($loop->have_posts()) : $loop->the_post(); $i++;?>      
                <?php $col_class='';
                if ($i==1) {
                     $col_class='full-width';
                 } else{
                    $col_class='half-width';
                 } ?>  
                    <article class="<?php echo $col_class; ?> <?php echo has_post_thumbnail() ? 'has-post-thumbnail' : 'no-post-thumbnail' ; ?>">
                        <?php if ($fixheight_post_count==true && !has_post_thumbnail()): ?>
                            <span class="post-num"><?php echo $i; ?></span>
                        <?php endif ?>
                        <div class="fixheight-item-wrapper">
                            <?php if (has_post_thumbnail()) : ?>
                                <div class="post-featured-image">
                                    <div class="featured-image" style="background-image: url('<?php the_post_thumbnail_url();?>');">
                                        <a href="<?php the_permalink();?>" class="post-thumbnail-link"></a>
                                        <?php $homepage_video_url = get_post_meta( get_the_ID(), 'new-blogbell-video-url', true ); ?>
                                        <?php if (!empty($homepage_video_url)): ?>
                                           <a href="<?php the_permalink();?>"> <div class="homepage-video-icon"><i class="fa fa-play"></i></div></a>
                                        <?php endif ?>
                                        <?php if ($fixheight_post_count==true): ?>
                                            <span class="post-num"><?php echo $i; ?></span>
                                        <?php endif ?>
                                    </div><!-- .featured-image -->
                                </div>
                            <?php endif; ?>
                            <div class="entry-container <?php echo esc_attr($content_align); ?>">
                                <?php if ( ($enable_category==true)) : ?>
                                    <div class="entry-meta entry-cat">
                                        <?php new_blogbell_entry_meta(); ?>
                                    </div><!-- .entry-meta -->
                                <?php endif; ?>
                                <header class="entry-header">
                                    <h2 class="entry-title"><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>
                                </header>
                                <?php if ((($enable_posted_on==true) || ($enable_author==true))) : ?>
                                    <div class="entry-meta">
                                        <?php 
                                            if (($enable_posted_on==true)) {
                                                new_blogbell_posted_on();
                                            } 
                                            if (($enable_author==true)) {
                                                new_blogbell_author();
                                            }
                                         ?>
                                    </div><!-- .entry-meta -->
                                <?php endif; ?>
                                <?php if (($enable_content==true)) : ?>
                                    <div class="entry-content">
                                        <?php
                                            $excerpt = new_blogbell_the_excerpt( $excerpt_length );
                                            echo wp_kses_post( wpautop( $excerpt ) );
                                        ?>
                                    </div><!-- .entry-content -->
                                <?php endif; ?>  
                            </div><!-- .entry-container -->
                        </div>
                    </article>

                <?php endwhile;?>
            <?php endif; ?>
            <?php wp_reset_postdata(); ?>
    </div>
</div>