<?php
/**
 * Blog section
 *
 * This is the template for the content of blog section
 *
 * @package Theme Palace
 * @subpackage Newstation
 * @since Newstation 1.0.0
 */
$options = newstation_get_theme_options();
if( $options['business_news_section_enable'] !== false ):

$content_details = array();

$post_ids = array();

    for ( $i = 1; $i <= 5; $i++ ) {
        if ( ! empty( $options['business_news_content_post_' . $i] ) )
            $post_ids[] = $options['business_news_content_post_' . $i];
    }

    $args = array(
        'post_type'         => 'post',
        'post__in'          => ( array ) $post_ids,
        'posts_per_page'    => absint( 5 ),
        'orderby'           => 'post__in',
        'ignore_sticky_posts'   => true,
        ); 

// Run The Loop.
$query = new WP_Query( $args );
if ( $query->have_posts() ) : 
    while ( $query->have_posts() ) : $query->the_post();
$page_post['id']        = get_the_id();
$page_post['title']     = get_the_title();
$page_post['url']       = get_the_permalink();
$page_post['image']  	= has_post_thumbnail() ? get_the_post_thumbnail_url( get_the_id(), 'large' ) : get_template_directory_uri() . '/assets/uploads/no-featured-image-590x650.jpg';

// Push to the main array.
array_push( $content_details, $page_post );
endwhile;
endif;
wp_reset_postdata();

$options = newstation_get_theme_options();

?>

<div id="business-news" class="relative">
    <div class="section-header">
        <?php if ( $options['business_news_title'] ): ?>

            <h2 class="section-title"><?php echo esc_html( $options['business_news_title'] ); ?></h2>

        <?php endif; ?>

        <?php if (!empty( $options['business_news_see_all_url'] ) && !empty( $options['business_news_see_all'] ) ): ?>

            <a href="<?php echo esc_url( $options['business_news_see_all_url'] ); ?>" class="btn">
                <?php echo esc_html( $options['business_news_see_all'] ); ?>
                <svg version="1.0" viewBox="0 0 14.000000 15.000000" preserveAspectRatio="xMidYMid meet">

                    <g transform="translate(0.000000,15.000000) scale(0.100000,-0.100000)" stroke="none">
                        <path d="M80 105 l23 -25 -51 0 c-29 0 -52 -4 -52 -10 0 -5 23 -10 52 -10 l51
                        0 -24 -28 c-15 -17 -11 -15 14 7 l37 35 -27 28 c-15 15 -31 28 -37 28 -5 0 1
                        -11 14 -25z"></path>
                    </g>
                </svg>
            </a>

        <?php endif; ?>

    </div><!-- .section-header -->

    <div class="business-news-post">

        <?php $i =1; foreach($content_details as $content):
        if ( $i == 1 ) {
            ?>

            <div class="business-news-full-width">
                <article>
                    <div class="business-news-wrapper">
                        <div class="featured-image" style="background-image: url('<?php echo esc_url( $content['image'] ); ?>');"></div>
                        <div class="entry-container">
                            <header class="entry-header">
                                <h2 class="entry-title"><a href="<?php echo esc_url( $content['url'] ); ?>"><?php echo esc_html( $content['title'] ); ?></a></h2>
                            </header>
                            <div class="entry-meta">
                                <?php newstation_posted_on( $content['id'] ); ?>
                                <?php the_category( '', '', $content['id'] ); ?>  
                            </div>
                        </div><!-- .entry-container -->
                    </div>
                </article>   
            </div> 

            <?php } $i++; endforeach; ?>

            <div class="business-news-sub-width col-2">

                <?php $j = 1; foreach($content_details as $content):
                if ( $j !== 1 ) {
                    ?>

                    <article>
                        <div class="business-news-wrapper">
                            <div class="featured-image" style="background-image: url('<?php echo esc_url( $content['image'] ); ?>');"></div>
                            <div class="entry-container">
                                <header class="entry-header">
                                    <h2 class="entry-title"><a href="<?php echo esc_url( $content['url'] ); ?>"><?php echo esc_html( $content['title'] ); ?></a></h2>
                                </header>
                                <div class="entry-meta">
                                    <?php newstation_posted_on( $content['id'] ); ?>
                                    <?php the_category( '', '', $content['id'] ); ?> 
                                </div>
                            </div><!-- .entry-container -->
                        </div>
                    </article>

                    <?php }
                    $j++; endforeach; ?>

                </div>
            </div>

        </div>

        <?php if (!empty( $options['business_ads_url'] ) && !empty( $options['business_ads_image'] )): ?>

            <div id="primary-ad-2" class="relative">
                <div class="featured-image">
                    <a href="<?php echo esc_url( $options['business_ads_url'] ); ?>"><img src="<?php echo esc_url( $options['business_ads_image'] ); ?>"></a>
                </div>
            </div>

        <?php endif; ?>

    <?php endif; ?>