<?php
/**
 * Template part for displaying front page imtroduction.
 *
 * @package Return Blog
 */
// Get the content type.
$blog = get_theme_mod( 'return_blog_blog', 'disable' );

if ( 'disable' === $blog ) {
    return;
}
$blog_count = 6;

$get_content = return_blog_get_section_content( 'blog', $blog, $blog_count  );
?>

<div id="sidebar-wrapper" class="pt padding">
    <div class="container">
        <?php if ( is_active_sidebar( 'blog-sidebar' ) ) { ?>
            <div id="primary" class="content-area">
        <?php } ?>
            <main id="main" class="site-main" role="main">
                <div>   
                 <div class="section-header">
                    <?php if (  !empty( get_theme_mod( 'return_blog_blog_title') ) ): ?>
                        <h2 class="section-title"><?php echo esc_html( get_theme_mod( 'return_blog_blog_title') ) ?></h2>
                    <?php endif ?>
                    <?php if ( !empty( get_theme_mod( 'return_blog_blog_sub_title') ) ): ?>
                        <p class="section-subtitle"><?php echo esc_html( get_theme_mod( 'return_blog_blog_sub_title') ) ?></p>
                    <?php endif ?>
                </div><!-- .section-header -->
                <div id="recent" class="col-2">
                    <?php foreach ($get_content as $content): ?>
                        <article>
                            <div class="post-item">
                                <div class="featured-image" style="background-image:url('<?php echo esc_url( get_the_post_thumbnail_url( $content['id'] ) ) ; ?>')"></div>
                                <div class="entry-container">
                                    <?php the_category( '', '', $content['id'] ) ?>

                                    <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-content">
                                        <p><?php echo esc_html( wp_trim_words( $content['content'], 30 ) ); ?> <a href="<?php echo esc_url( $content['url'] ) ?>">Read more</a></p>
                                    </div>

                                    <div class="entry-meta clear">
                                        <?php return_blog_post_author() ; ?>
                                        <?php return_blog_posted_on( $content['id'] ); ?>
                                    </div>
                                </div>
                            </div><!--.post-item -->
                        </article>
                    <?php endforeach ?>
                </div>
                <?php if ( get_theme_mod( 'return_blog_blog_btn_url', '' ) !== '' ): ?>
                    <div class="read-more">
                        <a href="<?php echo esc_url( get_theme_mod( 'return_blog_blog_btn_url' ) ) ;?>" class="btn">
                            <?php echo esc_html( get_theme_mod( 'return_blog_blog_btn_title', __('Load More', 'return-blog') ) ); ?>
                        </a>
                    </div>
                <?php endif ?>
            </main><!-- #main -->
            <?php if ( is_active_sidebar( 'blog-sidebar' ) ) { ?>
                </div><!-- #primary -->
            <?php } ?>
        <?php if ( is_active_sidebar( 'blog-sidebar' ) ) { ?>
        <aside id="secondary" class="widget-area" role="complementary">
            <?php
                dynamic_sidebar( 'blog-sidebar' );
            ?>
        </aside><!-- #secondary -->
    <?php } ?>
    </div><!-- .wrapper -->
</div><!-- #inner-content-wrapper-->
