<?php
/**
 * Template part for displaying front page imtroduction.
 *
 * @package Moral
 */

// Get the content type.
$travel_news = get_theme_mod( 'moral_magazine_travel_news', 'disable' );
$travel_news_num	= 4;
// Bail if the section is disabled.
if ( 'disable' === $travel_news ) {
	return;
}

$content_details = moral_magazine_get_section_content( 'travel_news', $travel_news, $travel_news_num );

?>
<div id="travel-news" class="relative primary-post travel_news">
    <?php if ( get_theme_mod( 'moral_magazine_travel_news_title', __( 'Travel News', 'moral-magazine' ) ) ): ?>
        <div class="section-header">
            <h2 class="section-title"><?php echo esc_html( get_theme_mod( 'moral_magazine_travel_news_title', __( 'Travel News', 'moral-magazine' ) ) ); ?></h2>
        </div>
    <?php endif ?>
    <div class="section-content">
        <?php foreach ( $content_details as $content ): ?>
            <article>
                <div class="travel-news-wrapper">
                    <div class="featured-image">
                        <img src="<?php echo esc_url( get_the_post_thumbnail_url( $content['id'] ) ) ; ?>">
                    </div><!-- .featured-image -->

                    <div class="entry-container">
                        <span class="cat-links"><?php the_category( '', '', $content['id'] ) ; ?></span>
                        <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 ) ) ; ?></p>
                        </div><!-- .entry-content -->
                        <div class="entry-meta">
                            <?php moral_magazine_posted_on( $content['id'] ) ; ?>
                            <span class="comment">
                                <a href="<?php echo esc_url( $content['url'] ) ; ?>">
                                    <i class="fa fa-comment" aria-hidden="true"></i><?php echo esc_html( get_comments_number( $content['id'] ) ); ?>
                                </a>
                            </span>
                            <span class="min-read"><?php echo moral_magazine_time_interval( $content['content'] ); echo esc_html__(' min read', 'moral-magazine'); ?></span>
                        </div>
                    </div>
                </div>
            </article>
        <?php endforeach ?>       
    </div>
</div><!-- #travel-news-aection -->

<?php if ( !empty( get_theme_mod( 'moral_magazine_travel_news_ads_image_url', '' ) ) ): ?>    
    <div id="primary-ad-1" class="relative primary-post">
        <div class="featured-image">
            <a href="<?php echo esc_url( get_theme_mod( 'moral_magazine_travel_news_ads_image_url' ) ); ?>">
                <img src="<?php echo esc_url( get_theme_mod( 'moral_magazine_travel_news_ads_image' ) ); ?>">
            </a>
        </div>
    </div>
<?php endif ?>
