<?php
$podcast_guru_options = podcast_guru_theme_options();





$episode_title = $podcast_guru_options['episode_title'];


$episode_desc = $podcast_guru_options['episode_desc'];



global $post;


?>



<?php 

if (podcast_guru_check_ssp_active()): 
        $args = array(
            'post_type'           => array( 'podcast' ),
            'post_status'         => array( 'publish' ),
            'posts_per_page'      => 6,
            'order'               => 'DESC',
            'orderby'             => 'date',
        );

    $podcast_query = new WP_Query($args);
    $loop = 0;

    if ($podcast_query->have_posts()): ?>

    <div class="card-list recent-episode section">
        <div class="container">
            <div class="row">
                <?php if ($episode_title || $episode_desc): ?>
                    <div class="section-title">
                        <?php

                        
                        
                        if ($episode_title)
                            echo '<h2>' . esc_html($episode_title) . '</h2>';
                            if ($episode_desc)
                            echo '<p>' . esc_html($episode_desc) . '</p>';
                        
                        ?>
                    </div>
                <?php endif; ?>
            </div>
        </div>

        <div class="container episode-container">
       
                <?php
                 $loop = 1;
                while ( $podcast_query->have_posts() ) :
                $podcast_query->the_post();
                echo(($loop % 3 == 1 || $loop == 1) ? '<div class="row">' : '');

                ?>
                <div class="col-md-4">
                    <div class="card">
                    <?php if ( has_post_thumbnail() ) : ?>
					<div class="episode-image">
						<?php the_post_thumbnail('podcast-guru-blog-thumbnail-img'); ?>
                        <div class="category-btn-wrap">
                            <?php 
                            $category = get_the_terms( $post->ID, 'series' ); 
                            if($category){     
                            foreach ( $category as $cat){ ?>
                            
                            <a class="category-button" href="<?php echo esc_url( get_term_link( $cat ) ) ?>">
                                        <?php echo $cat->name; ?>
                                    </a>
                            <?php }
                            }
                            ?>
                            </div>
                        </div>
					<?php endif; ?>

                    <div class="card-content">

                        <h3><a href="<?php echo esc_url(get_the_permalink()); ?>"><?php the_title(); ?></a></h3>
                           
                            
                    </div>
                           
                    </div>
                </div>
                            <?php echo(($loop % 3  == 0 && $loop != 1) ? '</div>' : '');
                        $loop++;
                endwhile; ?>
           </div>
        </div>
        
    </div>

    <?php endif;


    wp_reset_postdata(); 
    endif;
