<?php
/**
 * Template part for displaying sticky post content in the front page.
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package Blogbuster
 */

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

$blogbuster_front_sticky_post_enable    = blogbuster_get_customizer_option_value( 'blogbuster_front_sticky_post_enable' );

if ( true ==! $blogbuster_front_sticky_post_enable ) {
    return ;
}

$blogbuster_front_sticky_post_section_title = blogbuster_get_customizer_option_value( 'blogbuster_front_sticky_post_section_title' );

$sticky_posts = get_option( 'sticky_posts' );
        
if ( !empty( $sticky_posts ) ) {

?>
    <div class="mt-front-sticky-post-wrapper">

        <h2 class="mt-content-title"><?php echo esc_html( $blogbuster_front_sticky_post_section_title ); ?></h2>

        <?php
            $sticky_args = array(
                'posts_per_page'    => 1,
                'post__in'          => $sticky_posts,
                'ignore_sticky_posts' => 1
            );

            $sticky_query = new WP_Query( $sticky_args );
            if ( $sticky_query->have_posts() ) {
                while ( $sticky_query->have_posts() ) {
                    $sticky_query->the_post();
                    /*
                     * Include the Post-Type-specific template for the content.
                     * If you want to override this in a child theme, then include a file
                     * called content-___.php (where ___ is the Post Type name) and that will be used instead.
                     */
                    get_template_part( 'template-parts/content', 'sticky' );
                }
            }

        ?>

    </div><!-- .mt-front-sticky-post-wrapper -->
<?php
}