<?php

get_header();

// featured post
get_template_part('partials/content', 'categorymenu');
$featured = get_field('post_featured', 'option');
if (is_array($featured) && count($featured) > 0) {
    $categories = get_the_category($featured[0]->ID);
}

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$args = array(
    'post_status' => 'publish',
    'orderby'   => 'date',
    'order' => 'DESC',
    'post_type' => 'post',
    'paged' => $paged,
);
query_posts($args);

?>

<!-- MAIN -->
<div id="main" role="main" class="main-content v2 bg-white">
    <div class="blog-page">
        <?php
        if ($paged == 1 && is_array($featured)) : ?>
            <section class="blog-title blog-title__dark blog-title__featured  scroll-appear">
                <?php
                if (is_array(get_field('a_la_une', $featured[0]->ID))) : ?>
                    <div class="bg"><?php echo wp_get_attachment_image(get_field('a_la_une', $featured[0]->ID)['id'], 'full'); ?></div>
                <?php else : ?>
                    <div class="bg"><?php echo get_the_post_thumbnail($featured[0]->ID, 'full', ['class' => '']) ?></div>
                <?php endif; ?>

                <div class="wrapper relative ">
                    <?php if (!empty($categories)) {
                        echo '  <h2 class="uptitle">' . esc_html($categories[0]->name) . '</h2>';
                    } ?>
                    <h1 class="title">
                        <a href="<?php echo get_the_permalink($featured[0]->ID) ?>"><span><?php echo esc_html($featured[0]->post_title) ?></span></a>
                    </h1>
                </div>
            </section>
        <?php else : ?>
            <section class="blog-title  page-title  scroll-appear">
                <div class="wrapper">
                    <h1 class="title"><?php echo  __('les actualités', 'laurentperrier') ?></h1>

                </div>
            </section>
        <?php endif; ?>
        <?php get_template_part('partials/content', 'blog'); ?>
    </div>
    <?php get_template_part('partials/fixed', 'les_vins_relationel'); ?>
</div>

<?php get_footer(); ?>