<?php
    $mustread_title       = new_blogbell_get_option( 'mustread_title' );
    $mustread_subtitle       = new_blogbell_get_option( 'mustread_subtitle' );
    $mustread_content_type     = new_blogbell_get_option( 'mustread_content_type' );
    $enable_category     = new_blogbell_get_option( 'mustread_category_enable' );
    $enable_content     = new_blogbell_get_option( 'mustread_content_enable' );
    $enable_author     = new_blogbell_get_option( 'mustread_author_enable' );
    $enable_posted_on     = new_blogbell_get_option( 'mustread_posted_on_enable' );
    $number_of_mustread_items  = new_blogbell_get_option( 'number_of_mustread_items' );
    $mustread_category = new_blogbell_get_option( 'mustread_category' );
    $header_font_size = new_blogbell_get_option( 'mustread_font_size');
    $number_of_mustread_column = new_blogbell_get_option('number_of_mustread_column');
    $content_align = new_blogbell_get_option('mustread_content_align');
    $excerpt_length =new_blogbell_get_option( 'mustread_excerpt_length');
    $homepage_layout_options =new_blogbell_get_option( 'homepage_design_layout_options');

    $see_more_txt     = new_blogbell_get_option( 'mustread_see_all_txt' );
    $see_more_url     = new_blogbell_get_option( 'mustread_see_all_url' );

    for( $i=1; $i<=$number_of_mustread_items; $i++ ) :
        $mustread_page_posts[] = absint(new_blogbell_get_option( 'mustread_page_'.$i ) );
        $mustread_post_posts[] = absint(new_blogbell_get_option( 'mustread_post_'.$i ) );
    endfor;

?>
<style>
    <?php if ($header_font_size != 0): ?>
        #mustread .section-title{
            font-size:<?php echo esc_attr($header_font_size); ?>px;
        }
    <?php endif ?>
</style>
<?php if(!empty($mustread_title) ):?>
    <div class="section-header">
        <?php if (!empty($mustread_title)): ?>
            <h2 class="section-title"><?php echo esc_html($mustread_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) ?>"><?php echo esc_html($see_more_txt); ?></a>
            <?php endif ?>
        <?php endif; ?>
    </div>       
<?php endif;?>   

<div class="must-read-wrapper clear col-<?php echo esc_attr($number_of_mustread_column); ?> ">
    <?php 
        $args = array (
        'posts_per_page' =>absint( $number_of_mustread_items ),              
        'post_type' => 'post',
        'post_status' => 'publish',
        'paged' => 1,
        'ignore_sticky_posts' => true, 
        );
        if ( absint( $mustread_category ) > 0 ) {
            $args['cat'] = absint( $mustread_category );
        }
        $loop = new WP_Query($args);                        
        if ( $loop->have_posts() ) :
            $i=0;  
            while ($loop->have_posts()) : $loop->the_post(); $i++;?>        
                <article>
                    <div class="mustread-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( 'blog-thumbnails');?>');">
                                    <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 ?>
                                </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">
                                    <?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>
<?php 
    //ads
    $number_of_mustread_ads = new_blogbell_get_option( 'number_of_mustread_ads' );
    $mustread_col = new_blogbell_get_option( 'mustread_column_option' ); 
    $mustread_ads_enable = new_blogbell_get_option( 'disable_mustread_ads_section' ); 
?>
<?php if ($mustread_ads_enable==true): ?>
    <div class="site-advertisement <?php echo esc_attr($mustread_col); ?>">
        <?php for ($i=1; $i <= $number_of_mustread_ads ; $i++) { 
            $mustread_ads_img = new_blogbell_get_option( 'mustread_ads_img_'.$i ); 
            $mustread_ads_url = new_blogbell_get_option( 'mustread_ads_url_'.$i );
            ?>
            <span class="ads-info">
                <a target="_blank" href="<?php echo esc_url($mustread_ads_url) ?>"><img  src="<?php echo esc_url($mustread_ads_img) ?>"></a>
            </span>
        <?php } ?>
    </div>
<?php endif; ?>