I’m developing a custom template for a customer that wants in his website the possibility to filter posts by month.
After creating an archive.php page and placing the widget “Archives” in my sidebar I was able to loop and filter all the post published as he wanted but actually the last post of every month is not loaded.
Basically every post is filtered monthly but not the last one.
Here is my archive page with archive simple loop:
<?php get_header(); /** Template Name: Archivio */ ?>
<?php if ( have_posts() ) : the_post(); ?>
<section id="news-eventi">
<div class="container">
<div class="breadcrumb-site">
<div class="breadcrumbs" typeof="BreadcrumbList" vocab="http://schema.org/">
<h5 class="text-uppercase font-weight-light"><?php
if(function_exists('bcn_display')) {
bcn_display();
}
?></h5>
</div>
</div>
<div class="row border-left">
<div class="col-lg-9">
<div class="page-title">
<h1 class="text-uppercase"><?php if ( is_month() ) { echo 'ARCHIVIO NEWS: ' . get_the_date('F Y'); } ?></h1>
</div>
<!-- Start the Loop. -->
<?php if (have_posts() ): while ( have_posts() ) : the_post(); ?>
<div class="newsevent-container">
<div class="row mb-5">
<?php if ( has_post_thumbnail() ) { ?>
<div class="col-md-7">
<div class="newsevent-thumbnail-wrapper">
<div class="thumbnail">
<img src="https://wordpress.stackexchange.com/questions/316489/<?php echo get_the_post_thumbnail_url(); ?>" alt="Immagine di Copertina">
</div>
<div class="date">
<p class="day"><?php echo get_the_date('d'); ?></p>
<hr>
<p class="month"><?php echo get_the_date('m'); ?></p>
</div>
</div>
</div>
<div class="col-md-5">
<div class="newsevent-info-wrapper">
<hr>
<div class="newsevent-title">
<h6><?php the_title(); ?></h6>
</div>
<div class="excerpt">
<p><?php the_excerpt(); ?></p>
</div>
<div class="read-all-newsevent">
<a href="<?php the_permalink(); ?>">Leggi Tutto
<span>
<img src="<?php echo get_template_directory_uri(); ?>/images/icons/icon-link-right.svg">
</span>
</a>
</div>
</div>
</div>
<?php } else { ?>
<div class="col-md-2">
<div class="newsevent-thumbnail-wrapper newsevent-thumbnail-wrapper-no-thumbnail">
<div class="date">
<p class="day"><?php echo get_the_date('d'); ?></p>
<hr>
<p class="month"><?php echo get_the_date('m'); ?></p>
</div>
<div class="grey" style="height: 260px;"></div>
</div>
</div>
<div class="col-md-10">
<div class="newsevent-info-wrapper newsevent-info-wrapper-no-thumbnail">
<hr>
<div class="newsevent-title">
<h6><?php the_title(); ?></h6>
</div>
<div class="excerpt">
<p><?php the_excerpt(); ?></p>
</div>
<div class="read-all-newsevent">
<a href="<?php the_permalink(); ?>">Leggi Tutto
<span>
<img src="<?php echo get_template_directory_uri(); ?>/images/icons/icon-link-right.svg">
</span>
</a>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
<div class="col-lg-3">
<div class="sidenav">
<div class="sidenav-news-wrapper">
<div class="sidenav-newsevent sidenav-bando-content">
<?php dynamic_sidebar( 'Ultime News Sidebar' ); ?>
</div>
</div>
<div class="sidenav-newsletter">
<h5>NEWSLETTER</h5>
<p>Rimani in contatto con noi per ricevere aggiornamenti sulle nostre attività e sui bandi.</p>
<?php echo do_shortcode( 'Error: Contact form not found.
' ); ?>
</div>
</div>
</div>
</div>
</div>
</section>
<?php endif; ?>
<?php get_footer(); ?>
What am I doing wrong?
Any help will be appreciated guys.
Thanks.