<?php 
/**
 * Template part for displaying Trending Post Section
 *
 * @package Prime Magazine
 */
$prime_magazine_trending     = get_theme_mod( 'prime_magazine_trending_setting',true );
$prime_magazine_trending_post_slider_args = array(
  'post_type' => 'post',
  'post_status' => 'publish',
  'category_name' =>  get_theme_mod('prime_magazine_trending_post_slider_args'),
  'posts_per_page' => 6,
);

$prime_magazine_trending_post_title = get_theme_mod( 'prime_magazine_trending_post_title' );

?>
<?php if ( $prime_magazine_trending ){ ?>
<div class="trending_post">
  <h2 class="mb-5"><span><?php echo esc_html( $prime_magazine_trending_post_title ); ?><span></h2>
  <?php
  $prime_magazine_trending_post_slider_posts = new WP_Query( $prime_magazine_trending_post_slider_args );
  if ( $prime_magazine_trending_post_slider_posts->have_posts() ) :
    while ( $prime_magazine_trending_post_slider_posts->have_posts() ) :
      $prime_magazine_trending_post_slider_posts->the_post();
      ?>
      <div class="trending_post_inner mb-4 wow zoomInUp delay-1000" data-wow-duration="2s">
        <div class="row">
          <div class="col-lg-5 col-md-5 align-self-center">
            <?php if ( has_post_thumbnail() ) { ?>
              <img src="<?php the_post_thumbnail_url('full'); ?>" alt="<?php the_title_attribute(); ?>"/>
            <?php } else { ?>
              <img src="<?php echo esc_url( get_template_directory_uri() . '/images/default.png' ); ?>" alt="Default Image"/>
            <?php } ?>
          </div>
          <div class="col-lg-7 col-md-7 align-self-center">
            <div class="trending_post_inner_content">
              <?php
              // Get the categories of the post
              $categories = get_the_category();
              if ( ! empty( $categories ) ) {
                echo '<h4 class="front-post-category">' . esc_html( $categories[0]->name ) . '</h4>';
              }
              ?>
              <h3><a href="<?php echo esc_url( get_permalink( $post->ID ) ); ?>"><?php the_title(); ?></a></h3>
              <p><?php echo wp_trim_words( get_the_content(), 35 ); ?></p>
              <div class="entry-meta">
                <?php prime_magazine_posted_on(); ?>
              </div>
            </div>
          </div>
        </div>
      </div>
      <?php
    endwhile;
    wp_reset_postdata();
  endif;
  ?>
</div>
<?php } ?>
